springboot uses external tomcat startup mode
- 2021-12-11 17:58:48
- OfStack
Directory Startup Using External tomcat Startup Considerations Using External tomcat
Boot with external tomcat
Open the pom file and set the packaging format to war
<packaging>war</packaging>
SpringBoot has built-in tomcat running module by default, which can be started directly by main in Application (inherited from SpringBootServletInitializer).
The following configuration works in an external tomcat container
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<!-- If you are using your own tomcat Please comment below, if you use the 3 Square tomcat Don't comment below -->
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
Custom package name
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<warName>springboot</warName>
</configuration>
</plugin>
Use External tomcat Startup Considerations
springboot boots with an external tomcat
The default startup class inherits the SpringBootServletInitiailzer class and overrides the configure () method.
@SpringBootApplication
public class OpenApiApplicationextends SpringBootServletInitializer {
public static void main(String[] args) {
SpringApplication.run(OpenApiApplication.class, args);
}
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
return builder.sources(OpenApiApplication.class);
}
}