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>warpackaging>

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

<dependencies>
    
    <dependency>
        <groupId>org.springframework.bootgroupId>
        <artifactId>spring-boot-starter-tomcatartifactId>
        <scope>providedscope>
    dependency>
    
dependencies>

4.打包

mvn package

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

你可能感兴趣的:(spring,boot)