Spring Boot 2.0.2打包项目为war文件

1.修改启动类Application.Class,使其继承SpringBootServletInitializer类,并实现其configure方法

@SpringBootApplication
public class Application extends SpringBootServletInitializer {

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(Application.class);
    }

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

}

2.将pom.xml中的打包方式从jar变成war

<packaging>war</packaging>

3.将内嵌servlet容器(如tomcat)排除

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

4.打包

mvn package

参考:
https://docs.spring.io/spring-boot/docs/2.0.1.RELEASE/reference/htmlsingle/#howto-create-a-deployable-war-file

猜你喜欢

转载自blog.csdn.net/m0_37459945/article/details/80600718