Preface
The Springboot project is in the process of developing a built-in Tomcat,jetty container, and what happens when the project needs to be released.
Only two-step steps are required to modify the startup class, Inherit Springbootservletinitializer, and override the Configure method
/**
* Author: Meet small star
* email:tengxing7452@163.com
* date:17-5-10 * time
: a.m. 10:40
* Describe: Program Entry
*/
@SpringBootApplication
@EnableAutoConfiguration public
class Mainspringboot extends Springbootservletinitializer {
@Override
protected Springapplicationbuilder Configure ( Springapplicationbuilder application) {return
application.sources (mainspringboot.class);
}
Modifying Pom.xml files
<!--<packaging>jar</packaging>-->
<packaging>war</packaging>
Tomcat plug-in Dependency pack add Lifecycle privided
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId> spring-boot-starter-tomcat</artifactid>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId> tomcat-embed-jasper</artifactid>
<scope>provided</scope>
</dependency>
Concluding remarks
The Springbootservletinitializer class implements the Webapplicationinitializer interface, while the Webapplicationinitializer has a void OnStartup ( ServletContext var1) method
void Onstartup (ServletContext var1) throws servletexception;
Springbootservletinitializer implements this Onstartup method, mainly responsible for loading the related configuration when the container is started
public void Onstartup (ServletContext servletcontext) throws Servletexception {
This.logger = Logfactory.getlog ( This.getclass ());
Final Webapplicationcontext Rootappcontext = This.createrootapplicationcontext (ServletContext);
if (Rootappcontext!= null) {
Servletcontext.addlistener (new Contextloaderlistener (rootappcontext) {
public void Contextinitialized (Servletcontextevent event) {
}}
);
else {
this.logger.debug ("No Contextloaderlistener registered, as Createrootapplicationcontext () did Application Context ");
}
}
Code
Servletcontext.addlistener (New Contextloaderlistener (rootappcontext) {public
void contextinitialized ( Servletcontextevent event) {
}
});
The Servletcontextlistener interface is implemented in the
Contextloaderlistener, so that the related configuration under Springboot Project can be loaded by AddListener ().