📘 Premium Read: Access my best content on Medium member-only articles — deep dives into Java, Spring Boot, Microservices, backend architecture, interview preparation, career advice, and industry-standard best practices.
✅ Some premium posts are free to read — no account needed. Follow me on Medium to stay updated and support my writing.
🎓 Top 10 Udemy Courses (Huge Discount): Explore My Udemy Courses — Learn through real-time, project-based development.
▶️ Subscribe to My YouTube Channel (172K+ subscribers): Java Guides on YouTube
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
Comments
Post a Comment
Leave Comment