In this quick article, we will discuss the usage and importance of SpringBootServletInitializer class in Spring boot. This SpringBootServletInitializer class belongs org.springframework.boot.web.servlet.support package.
SpringBootServletInitializer Class
SpringBootServletInitializer Class Diagram
SpringBootServletInitializer Class Methods
- protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) - Configure the application.
- protected WebApplicationContext createRootApplicationContext(ServletContext servletContext)
- protected SpringApplicationBuilder createSpringApplicationBuilder() - Returns the SpringApplicationBuilder that is used to configure and create the SpringApplication.
- void onStartup(ServletContext servletContext)
- protected WebApplicationContext run(SpringApplication application) - Called to run a fully configured SpringApplication.
- protected void setRegisterErrorPageFilter(boolean registerErrorPageFilter) - Set if the ErrorPageFilter should be registered.
SpringBootServletInitializer Class Usage (Example)
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
@SpringBootApplication
public class Application extends SpringBootServletInitializer{
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(Springboot2WebappJspApplication.class);
}
public static void main(String[] args) {
SpringApplication.run(Springboot2WebappJspApplication.class, args);
}
}
mvn clean install
Check out all spring boot articles, guides, and tutorials at Top Spring Boot Tutorials
Reference
Continue Learning with Java Guides
Want to take your programming skills to the next level? Explore my practical Udemy courses on Java, Spring Boot, Microservices, Full-Stack Development, Docker, and Generative AI. You can also follow my structured learning roadmaps to become a professional developer.
By Ramesh Fadatare - Udemy Instructor Partner

Comments
Post a Comment
Leave Comment