spring boot 配置外接tomcat

ye___li發表於2020-06-03

maven pom.xml配置:

<!-- 1.配置打包為war  -->
<packaging>war</packaging>

<!--  2.移除嵌入式tomcat外掛  -->
         <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>


<!-- 3. 新增servlet依賴 外接tomcat-->
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>3.1.0</version>
            <scope>provided</scope>
        </dependency>

<!-- 4.設定 web.xml -->
  <plugin>
    <artifactId>maven-war-plugin</artifactId>
       <version>2.6</version>
          <configuration>
               <!--如果想在沒有web.xml檔案的情況下構建WAR,請設定為false。-->
                 <failOnMissingWebXml>false</failOnMissingWebXml>
          </configuration>
  </plugin>

2.啟動類繼承SpringBootServletInitializer實現configure

@SpringBootApplication
public class TestApplicationextends SpringBootServletInitializer {
 
    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder springApplicationBuilder) {
        return springApplicationBuilder.sources(TestApplication.class);
    }

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


}

 

相關文章