Table of contents
1. Abnormal error
The Springboot project uses IntelliJ IDEA to pack the maven project into a war package, and the pom.xml file introduces dependencies
And after packaging through the maven package, put it under the web-apps file of tomcat
At the same time, the server.xml file under the conf folder was modified, and the following problems occurred when starting tomcat
Two, the reason
SpringApplicationBuilder is used to build Spring applications. It is a builder for SpringApplication and ApplicationContext instances, with convenient and fluent API and context hierarchy support. If SpringApplicationBuilder is not added to the startup class, tomcat will not be able to build SpringBoot applications.
3. Solutions
required in the startup class
- Inherit the org.springframework.boot.context.web.SpringBootServletInitializer class
- Override configure(SpringApplicationBuilder application) method
public class CExperimentPlatformApplication extends SpringBootServletInitializer {
public static void main(String[] args) {
SpringApplication.run(CExperimentPlatformApplication.class, args);
}
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
return builder.sources(CExperimentPlatformApplication.class);
}
}