SpringBoot项目-使用外部Tomcat启动

我用的SpringBoot版本

parent>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-parent</artifactId>
   <version>2.5.2</version>
   <relativePath/> <!-- lookup parent from repository -->
/parent>
  1. 修改pom.xml文件
<packaging>war</packaging>

修改依赖

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
    <exclusions>
        <exclusion>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
        </exclusion>
    </exclusions>
</dependency>
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-tomcat</artifactId>
    <!--tomcat范围改成provided,告诉它,已经有外部tomcat了,不需要一起打包带走了-->
    <scope>provided</scope>
</dependency>
  1. 修改启动类,继承SpringBootServletInitializer ,并重写configure方法
public class JavaTestApplication extends SpringBootServletInitializer {

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

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
        return builder.sources(JavaTestApplication.class);
    }
}
  1. 启动项配置
    SpringBoot项目-使用外部Tomcat启动
    SpringBoot项目-使用外部Tomcat启动

参考链接:https://blog.csdn.net/u012939253/article/details/105530682

上一篇:第七章 服务监控之spring-boot-admin


下一篇:springboot+mybatis-plus+oracle项目搭建