springboot 以war包形式运行

1.将springboot默认的tomcat禁用


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

2.添加一个不为人知的插件


                org.apache.maven.plugins
                maven-surefire-plugin
                2.4.2
                
                    true
                
 

3.把jar改成war

war

4.main方法继承SpringBootServletInitializer 实现 SpringApplicationBuilder

@SpringBootApplication
public class DemoApplication extends SpringBootServletInitializer{
    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
        return builder.sources(DemoApplication.class);
    }

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

你可能感兴趣的:(springboot 以war包形式运行)