springboot 以war包形式运行

2019-04-13  本文已影响0人  唯爱米

1.将springboot默认的tomcat禁用

<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
            <scope>provided</scope>
</dependency>

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

<plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.4.2</version>
                <configuration>
                    <skipTests>true</skipTests>
                </configuration>
 </plugin>

3.把jar改成war

<packaging>war</packaging>

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);
    }
}
上一篇下一篇

猜你喜欢

热点阅读