Spring Boot项目打包部署到外部Tomcat

1、生成war包

  1)修改POM文件,将打包类型改为war:war

<packaging>warpackaging>

  (2)添加spring-boot-starter-tomcat依赖,scope设置为provided

<dependency>
        <groupId>org.springframework.bootgroupId>
        <artifactId>spring-boot-starter-tomcatartifactId>
        <scope>providedscope>
dependency>

  (3)注册启动类

    创建ServletInitializer.java,继承SpringBootServletInitializer ,覆盖configure(),把启动类Application注册进去。外部web应用服务器构建Web Application Context的时候,会把启动类添加进去。

public class ServletInitializer  extends SpringBootServletInitializer {
    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(BootdemoApplication.class);
    }
}

  (4)通过IDEA的Maven工具生成,点击run as ---maven install,生成war,可以直接拷到tomcat的webapps目录下,启动Tomcat即可。

    注意同一端口号的多个项目部署时,在tomcat/config/server.xml中添加,如:

<Context path="/route" reloadable="true" docBase="/home/develop/tomcat-7.0.54/webapps"/>  
<Context path="/route2" reloadable="true" docBase="/home/develop/tomcat-7.0.54/webapps"/>  

    通过访问:http://127.0.0.1:8080/route  http://127.0.0.1:8080/route2 对应各子的项目

 

转载于:https://www.cnblogs.com/conswin/p/7810523.html

你可能感兴趣的:(Spring Boot项目打包部署到外部Tomcat)