SpringBoot2.0.4 deployed in tomcat container

1. Modify the startup class inherits from SpringBootServletInitializer.

2. rewrite config method:

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

3. Add references in the pom file

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

<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.1.0</version>
<scope>provided</scope>
</dependency>

4. Modify war package compiled

<packaging>war</packaging>

5. The resulting package name modified to war and put ROOT.war webapps below.

6. Start.

7. A summary of the problem:

  • In tomcat deployment must first rule springboot comes tomcat, there are two ways:

             First with <exclusions>, the second introduction tomcat package.

  • jak version match the version of tomcat

             jdk1.7 generally corresponds tomcat7.X

             jdk1.8 generally corresponds tomcat8.X

If the project refer to other jar package, will be reported at boot time error NoSuchClassFound, such as:

This means that we used ElasticSearch, you must use tomcat8 to start.

 

 
 
 
 

 

Guess you like

Origin www.cnblogs.com/baoyi/p/springboot_tomcat.html