SpringBoot deploy the project to an external configuration of Tomcat

  In the development phase we recommend using embedded tomcat for development, because it will be a lot easier, but to build environment, you need to deploy the project to Tomcat to run outside, this time need some extra configuration:

1.pom.xml adjustment

1.1 modify packaging

<packaging>jar</packaging>

Change

<packaging>war</packaging>

1.2 The range of spring-boot-starter-tomcat is provided to

  scope is set provided, the built springboot Tomcat preclude the packing

 <dependency>
     <groupId>org.springframework.boot</groupId>
     <artifactId>spring-boot-starter-tomcat</artifactId>
     <scope>provided</scope>
  </dependency>

 It found that the project is not configured in the above configuration, because the transitive dependencies within the tomcat spring-boot-starter-web, we need to manually transfer together with the cover dependent configuration

2. Modify the startup class

  Inheritance SpringBootServletInitializer cover configure method, example:

public class Application extends SpringBootServletInitializer {

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
        return builder.sources(Application.class);
    }
    
    public static void main(String[] args) {
        new SpringApplicationBuilder(Application.class).web(true).run(args);
    }
}

3. Modify the access path project

   Use SpringBoot development built Tomcat runtime, often do not use direct access project name, if deployed outside the Tomcat will be a problem, then you can do the following configuration:

  Modify server.xml file

    In the installation path Tomcat conf server.xml file folder found <Host> </ Host> tags, added in its interior

< The Host > 
    < the Context docBase = "D: \ the Tomcat \ Apache Tomcat-9.0.24-\ the webapps \ ERP" path = "" Reloadable = "to true" the crossContext = "to true" /> // where docBase war package in the project webapps address 
</ the Host >

 


 

Configuration complete!

 

Guess you like

Origin www.cnblogs.com/autism-dong/p/12623857.html