How to deploy external Tomcat process based on springboot

Time:2021-5-7

This article mainly introduces the process analysis of spring boot deployed to external Tomcat in the form of war package. The sample code is introduced in great detail in this article, which has a certain reference learning value for everyone’s study or work. Friends who need it can refer to it

Springboot projects can be packaged as. Jar and. War package files. Jar can be started by using java – jar XX. Jar, and. War can be deployed to Tomcat webapps and started with Tomcat.

Springboot itself is built-in Tomcat. If you want to deploy to external tomcat, you need to make some changes.

1. Change packaging to war in POM file

1 <packaging>war</packaging>

2. Exclude Tomcat in Maven

The first kind

<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-web</artifactId>
  <exclusions><!--  Remove embedded Tomcat plug-in -- >
    <exclusion>
    <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-tomcat</artifactId>
    </exclusion>
   </exclusions>
</dependency>

The second kind

<!--  If a third-party Tomcat is used, please add scope -- >
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-tomcat</artifactId>
    <scope>provided</scope>
</dependency>

3. Inherit springbootservletinitializer from application.java and rewrite the configure method


@SpringBootApplication
public class DemoApplication extends SpringBootServletInitializer {

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

  @Override
  protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
    return builder.sources(DemoApplication.class);
  }
}

4. Use MVN clean package or editor to package as war package

The above is the whole content of this article, I hope to help you learn, and I hope you can support developer more.

Recommended Today

Mongodb aggregate

  https://www.cnblogs.com/wt7018/p/11929359.html Mongodb aggregate   1、 Foundation 1. What is aggregation? Aggregation is an aggregation pipeline based on data processing. Each document passes through a pipeline composed of multiple stagesIt can group and filter the pipelines in each stage, and then output the corresponding results after a series of processing DB. Set name. Aggregate ({pipeline: […]