springboot 整合外部tomcat war包部署方式

FH-Admin發表於2021-08-09

1. pom

    <groupId>org.fh</groupId>
    <artifactId>xxxx</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>war</packaging><!-- 以war執行是改成war -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <!-- 移除嵌入式tomcat外掛  war包方式部署時,解開註釋fhadmin.cn  -->

            <exclusions>
                <exclusion>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-tomcat</artifactId>
                </exclusion>
            </exclusions>

        </dependency>
    <build>
        <finalName>fhadmin</finalName>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <version>1.4.2.RELEASE</version><!-- springboot專案打jar包執行 外掛版本只能是1.4.2.RELEASE fhadmin.cn-->
                <configuration>
                <mainClass>org.fh.FHmainApplication</mainClass><!--入口類-->
                </configuration>
            </plugin>
        </plugins>
        <resources>
            <resource>
                <directory>${basedir}/src/main/webapp</directory>
                <targetPath>META-INF/resources</targetPath>
                <includes>
                    <include>**/**</include>
                </includes>
            </resource>
            <resource>
                <directory>src/main/resources</directory>
                <filtering>false</filtering>
                <includes>
                    <include>**/**</include>
                </includes>
            </resource>
        </resources>
    </build>

2. 在和啟動類評級上新增類

package org.fh;

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

/**
 * 說明:專案以war包方式執行時用到
 * 作者:FH Admin
 * from  fhadmin.cn
 */
public class SpringBootStartApplication extends SpringBootServletInitializer {

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
        return builder.sources(FHmainApplication.class);  //這裡要指向原先用main方法執行的FHmainApplication啟動類
    }
}
本作品採用《CC 協議》,轉載必須註明作者和本文連結

相關文章