配置springboot專案使用外部tomcat

weixin_30729609發表於2019-08-11

配置springboot專案使用外部tomcat

1.在pom檔案中新增依賴

<!--使用自帶的tomcat-->
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-tomcat</artifactId>
    <scope>provided</scope>
</dependency>

2.在Springboot自帶的Application啟動類所在目錄下新建啟動類SpringBootStartApplication

package com.huang;

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

//讓該類繼承springboot的SpringBootServletInitializer
public class SpringBootStartApplication extends SpringBootServletInitializer {

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application){
        //找到原先的啟動類
        return application.sources(WebchatApplication.class);
    }
}
#目錄如下
src
 |-main
    |-java
        |-com.huang.sockerservice
        |-WebchatApplication.class #原本的啟動類
        |-SpringBootStartApplication.class #新的啟動類
    |-resources

轉載於:https://www.cnblogs.com/Createsequence/p/11335688.html

相關文章