1. 程式人生 > >springboot專案打成war包使用Tomcat或者其他容器啟用

springboot專案打成war包使用Tomcat或者其他容器啟用

研究了不使用springboot自帶內建Tomcat啟動.放入自己web容器啟動.


  1. 工具 :idea springboot專案

  2. 開始配置pom
    打包方式jar 改成war
<packaging>war</packaging> //
    <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>javax.servlet</groupId> <artifactId>javax.servlet-api</artifactId> <version>3.1.0</version> <scope>provided</scope> </dependency>

3.新增啟動類

import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.support.SpringBootServletInitializer;

/**
 *
 *
 * @Filename: start
 * Description:
 * @Version: 1.0
 * @Author: whyloveit
 * @Date: 2017/12/19
 */
public class start extends SpringBootServletInitializer {

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
        // 注意這裡要指向原先用main方法執行的Application啟動類
        return builder.sources(TravelEurekaProviderApplication.class);
    }
}