📘 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.
🎓 Top 15 Udemy Courses (80-90% Discount): My Udemy Courses - Ramesh Fadatare — All my Udemy courses are real-time and project oriented courses.
▶️ Subscribe to My YouTube Channel (176K+ subscribers): Java Guides on YouTube
▶️ For AI, ChatGPT, Web, Tech, and Generative AI, subscribe to another channel: Ramesh Fadatare 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