SpringBoot项目war包部署

1. pom.xml的修改

      <!-- 设置打包方式为war包 -->
    <packaging>war</packaging>
<dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <!-- 移除嵌入式tomcat插件 -->
            <exclusions>
                <exclusion>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-tomcat</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

      <!-- 添加该依赖 -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
            <scope>provided</scope>
        </dependency>
</dependencies>

2. 修改启动类

继承SpringBootServletInitializer,实现configure方法

@SpringBootApplication
public class DemoApplication extends SpringBootServletInitializer {

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

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

参考

SpringBoot项目的创建和jar、war方式的部署
SpringBoot War包形式部署到外部Tomcat

posted @ 2020-05-10 16:51  if年少有为  阅读(410)  评论(0编辑  收藏  举报