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

1、生成war包

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

<packaging>war</packaging>

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

<dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-tomcat</artifactId>
        <scope>provided</scope>
</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 对应各子的项目

 

posted @ 2017-11-09 17:28  寻的足迹  阅读(3530)  评论(0编辑  收藏  举报