springboot(8)——SpringBoot项目打war包

一、pom.xml中修改成war打包方式
 <packaging>warpackaging>
二、移除嵌入式tomcat插件两种方式
<dependency>
    <groupId>org.springframework.bootgroupId>
    <artifactId>spring-boot-starter-webartifactId>
    
    <exclusions>
        <exclusion>
            <artifactId>spring-boot-starter-tomcatartifactId>
            <groupId>org.springframework.bootgroupId>
        exclusion>
    exclusions>
dependency>


<dependency>
    <groupId>org.apache.tomcatgroupId>
    <artifactId>tomcat-servlet-apiartifactId>
    <scope>providedscope>
dependency>
三、添加servlet-api的依赖
<dependency>
    <groupId>javax.servletgroupId>
    <artifactId>javax.servlet-apiartifactId>
    <scope>providedscope>
dependency>
四、修改启动类,重写初始化方法

增加war包的启动类, XXXApplication.class 是原来的启动类

public class WarStartApplication extends SpringBootServletInitializer {
    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
        return builder.sources(XXXApplication.class);
    }
}
五、执行maven install 打包

你可能感兴趣的:(springboot学习笔记,spring,boot,java,后端)