Spring Boot改为打war包方式

  1. 相应模块的pom.xml中project节点下增加或修改打包方式(不要修改父模块)
war

2.pom.xml中dependencies节点下增加或修改tomcat相关包配置


    org.springframework.boot
    spring-boot-starter-tomcat
    provided    

3.pom.xml中build节点下增加或修改打包文件名(非必要)

messagerouter

4.修改Application类,需要继承SpringBootServletInitializer,重写configure方法

@SpringBootApplication
public class MessageRouterApplication extends SpringBootServletInitializer {

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
        return builder.sources(MessageRouterApplication.class);
    }

    public static void main(String[] args) {
        SpringApplication.run(MessageRouterApplication.class, args);
    }
}

5.最后执行mvn package就可以直接生成war包了.

附完整pom.xml:



    4.0.0
    
        org.springframework.boot
        spring-boot-starter-parent
        2.3.2.RELEASE
         
    
    com.hzwm
    messagerouter
    1
    messagerouter
    messagerouter
    war

    
        1.8
    

    
        
            org.springframework.boot
            spring-boot-starter-web
        
        
            org.springframework.boot
            spring-boot-starter-tomcat
            provided
        
        
            org.springframework.boot
            spring-boot-starter-test
            test
            
                
                    org.junit.vintage
                    junit-vintage-engine
                
            
        
        
            com.aliyun
            aliyun-java-sdk-core
            4.5.1
        
        
            com.alibaba
            fastjson
            1.2.73
        
        
            com.aliyun
            aliyun-java-sdk-dysmsapi
            2.1.0
        
        
            org.projectlombok
            lombok
        
    

    
        messagerouter
        
            
                org.springframework.boot
                spring-boot-maven-plugin
            
        
    



你可能感兴趣的:(Spring Boot改为打war包方式)