欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

spring boot 打 war包

程序员文章站 2022-07-05 08:36:45
spring boot 、spring cloud打 war包,并发布到tomcat中运行 ......
spring boot 、spring cloud打 war包,并发布到tomcat中运行
1、pom文件修改
<packaging>war</packaging>
2、<!-- 移除嵌入式tomcat插件 -->
<dependency>
    <groupid>org.springframework.boot</groupid>
    <artifactid>spring-boot-starter-web</artifactid>
    <exclusions>
        <exclusion>
            <groupid>org.springframework.boot</groupid>
            <artifactid>spring-boot-starter-tomcat</artifactid>
        </exclusion>
    </exclusions>
</dependency>

 

3、增加两个依赖
<dependency>
    <groupid>javax.servlet</groupid>
    <artifactid>javax.servlet-api</artifactid>
    <version>3.1.0</version>
    <scope>provided</scope>
</dependency>
<dependency>
    <groupid>org.apache.tomcat</groupid>
    <artifactid>tomcat-servlet-api</artifactid>
    <version>8.0.36</version>
    <scope>provided</scope>
</dependency>
 
4、新增一个类或直接在application类中继承springbootservletinitializer类并复写configure方法

 

import org.springframework.boot.builder.springapplicationbuilder;
import org.springframework.boot.web.servlet.support.springbootservletinitializer;
/**
 * 
* copyright: copyright (c) 2019 wudg
* 
* @classname: servletinitializer.java
* @description:将项目打包成war则需要集成springbootservletinitializer并复写configure方法
* @version: v1.0.0
* @author: wudg
* @date: 2019/08/13 15:50

*/
public class servletinitializer extends springbootservletinitializer {
    
    @override
    protected springapplicationbuilder configure(springapplicationbuilder application) {
        return application.sources(demoapplication.class);
    }
}

 

 推荐两份官方文档
spring boot
spring cloud