spring boot 打 war包


spring boot 、spring cloud打 war包,并发布到tomcat中运行
1、pom文件修改
<packaging>war</packaging>
2、<!-- 移除嵌入式tomcat插件 -->
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
    <exclusions>
        <exclusion>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
        </exclusion>
    </exclusions>
</dependency>

 

3、增加两个依赖
<dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>javax.servlet-api</artifactId>
    <version>3.1.0</version>
    <scope>provided</scope>
</dependency>
<dependency>
    <groupId>org.apache.tomcat</groupId>
    <artifactId>tomcat-servlet-api</artifactId>
    <version>8.0.36</version>
    <scope>provided</scope>
</dependency>
 
4、新增一个类或直接在Application类中继承SpringBootServletInitializer类并复写configure方法

 

import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
/**
 * 
* Copyright: Copyright (c) 2019 WuDG
* 
* @ClassName: ServletInitializer.java
* @Description:将项目打包成war则需要集成SpringBootServletInitializer并复写configure方法
* @version: v1.0.0
* @author: WuDG
* @date: 2019/08/13 15:50

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

 

 推荐两份官方文档
Spring Cloud

 

 

 

 
 

作者:WuDG,发布于:2019/08/13
原文:https://www.cnblogs.com/RoronoaZoro/p/11346365.html