springboot 集成外部tomcat war包部署方式

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启动类
    }
}

 

上一篇:bash shell中的数学计算


下一篇:spring-cloud-alibaba 组件版本关系