【问题标题】:Deploying Spring boot war to Tomcat 8将 Spring Boot War 部署到 Tomcat 8
【发布时间】:2016-03-01 20:45:10
【问题描述】:

我想将我的 Spring 启动应用程序 (.war) 部署到外部 Tomcat-Server。我的应用程序在 Eclipse 中使用本地 Tomcat 8 和 jdk 8 运行良好。此外,我们正在使用 maven 和

现在我们必须从头开始设置整个服务器,并且我们尽力做到最好,但应用程序找不到任何服务。我们只能调用静态的html、css和js文件。就我们想要调用服务而言,我们会收到 404 错误。

谁能告诉我逐步设置tomcat并部署战争?

这是我的开始类:

@PropertySources({
        @PropertySource("classpath:/application.properties"),
        @PropertySource("classpath:/messages_de.properties")
})
@SpringBootApplication
public class Application {
    public static void main(String[] args) throws Exception {
        SpringApplication springApplication = new SpringApplication(Application.class);
        springApplication.run(args);
    }
}

这里是 pom.xml...

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>de.quanto</groupId>
    <artifactId>QuantoSpringMVC</artifactId>
    <packaging>war</packaging>
    <version>0.0.1-SNAPSHOT</version>
    <name>QuantoSpringMVC Maven Webapp</name>
    <url>http://maven.apache.org</url>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.3.2.RELEASE</version>
    </parent>
    <dependencies>
        <dependency>
            <groupId>javax</groupId>
            <artifactId>javaee-web-api</artifactId>
            <version>7.0</version>
            <scope>provided</scope>
        </dependency>
        <!-- for JPA, use hibernate-entitymanager instead of hibernate-core -->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.36</version>
        </dependency>
        <dependency>
            <groupId>org.eclipse.persistence</groupId>
            <artifactId>org.eclipse.persistence.jpa</artifactId>
            <version>2.6.1-RC1</version>
        </dependency>
        <dependency>
            <groupId>javax.persistence</groupId>
            <artifactId>persistence-api</artifactId>
            <version>1.0.2</version>
        </dependency>
        <!-- Used for generating hibernate-model classes >>> -->
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-tools</artifactId>
            <version>4.3.2.Final</version>
            <scope>compile</scope>
            <exclusions>
                <exclusion>
                    <artifactId>log4j</artifactId>
                    <groupId>log4j</groupId>
                </exclusion>
                <exclusion>
                    <artifactId>slf4j-api</artifactId>
                    <groupId>org.slf4j</groupId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.eclipse.equinox</groupId>
            <artifactId>app</artifactId>
            <version>1.3.200-v20130910-1609</version>
        </dependency>
        <!-- <<< -->
        <!-- SPRING DEPENDENCIES/REPO/PLUGINS STARTS HERE -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <exclusions>
                <exclusion>
                    <artifactId>jcl-over-slf4j</artifactId>
                    <groupId>org.slf4j</groupId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
            <exclusions>
                <exclusion>
                    <artifactId>slf4j-api</artifactId>
                    <groupId>org.slf4j</groupId>
                </exclusion>
                <exclusion>
                    <artifactId>jcl-over-slf4j</artifactId>
                    <groupId>org.slf4j</groupId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <version>1.3.2.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
            <version>${springframework.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
            <version>${springframework.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>${springframework.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-orm</artifactId>
            <version>${springframework.version}</version>
        </dependency>
        <!-- SECURITY START -->
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-core</artifactId>
            <version>4.0.3.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-web</artifactId>
            <version>4.0.3.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-config</artifactId>
            <version>4.0.3.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>commons-dbcp</groupId>
            <artifactId>commons-dbcp</artifactId>
            <version>1.4</version>
        </dependency>
        <!-- SECURITY ENDS -->
        <!-- Authentification (Access Directory...) -->
        <dependency>
            <groupId>org.springframework.security.oauth</groupId>
            <artifactId>spring-security-oauth2</artifactId>
            <version>2.0.8.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.modelmapper</groupId>
            <artifactId>modelmapper</artifactId>
            <version>0.7.5</version>
        </dependency>
        <dependency>
            <groupId>org.modelmapper.extensions</groupId>
            <artifactId>modelmapper-spring</artifactId>
            <version>0.7.5</version>
        </dependency>
    </dependencies>
    <properties>
        <springframework.version>4.2.4.RELEASE</springframework.version>
        <java.version>1.7</java.version>
        <tomcat.version>8.0.32</tomcat.version>
    </properties>
    <repositories>
        <repository>
            <id>spring-releases</id>
            <url>https://repo.spring.io/libs-release</url>
        </repository>
    </repositories>
    <pluginRepositories>
        <pluginRepository>
            <id>spring-releases</id>
            <url>https://repo.spring.io/libs-release</url>
        </pluginRepository>
    </pluginRepositories>
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
        <finalName>QuantoSpringMVC</finalName>
    </build>
</project>

【问题讨论】:

    标签: java eclipse spring maven tomcat


    【解决方案1】:

    您需要使用新更改的文本更新您的经理网址

    <plugin>
                    <groupId>org.apache.tomcat.maven</groupId>
                    <artifactId>tomcat8-maven-plugin</artifactId>
                    <version>{version}</version>
                    <configuration>
                        <url>http://yourRemoteServer:8888/manager/text</url>
                        <server>TomcatServer</server>
                        <path>/{project.artifactId}</path>
                    </configuration>
                </plugin>
    

    现在你可以运行 mvn tomcat7:deploy( 或 redeploy)

    PS :我知道命令 tomcat7:deploy (redeploy) 存在,但我不确定 tomcat8:deploy !

    【讨论】:

    • 会不会是我的网址以 manager/html 结尾?我还需要在这个插件中自定义什么?我正在使用 Eclipse 中的“maven install”,然后在 tomcat manager gui 的帮助下部署 .war。这行得通吗?
    • 此方法考虑使用插件tomcat。对于插件,扩展名\text 是关于部署 tomcat 6 和 tomcat 7 的更新。不幸的是,我知道这个解决方案,但是如果您尝试直接使用您的经理 gui 进行部署,我不确定这是否可行。
    • 它正在工作。我们安装了正确的 java 8 版本。然后在 pom.xml 中设置上面的代码,使用“maven install”并通过 gui 上传。
    • 重要的是:您不能覆盖 .war 文件。您需要取消显式部署,然后部署新的...这是我尝试通过 gui 部署时的最大错误。
    • 我已经知道了!我个人更喜欢在tomcat的~\webapp下手动部署!当我想重新部署时,我删除了~\webapp~\work\Catalina\localhost 下的旧版本并删除了新版本
    猜你喜欢
    • 2015-03-10
    • 2018-12-05
    • 2020-06-17
    • 2018-05-18
    • 1970-01-01
    • 2017-01-04
    • 2016-08-11
    • 2014-09-04
    • 2016-01-16
    相关资源
    最近更新 更多