How can I disable the DispatcherServlet on SpringBoot, even trying to disable it via servlet registration the uri mapping appears on the log:
@Bean
public ServletRegistrationBean servletRegistrationBean(final DispatcherServlet dispatcherServlet) {
final ServletRegistrationBean servletRegistrationBean = new ServletRegistrationBean(dispatcherServlet);
servletRegistrationBean.setEnabled(false);
return servletRegistrationBean;
}
LOG
2015-06-10 10:39:57.552 INFO 7032 --- [ main] o.s.b.c.e.ServletRegistrationBean : Servlet dispatcherServlet was not registered (disabled)
2015-06-10 10:39:57.553 INFO 7032 --- [ main] o.s.b.c.e.ServletRegistrationBean : Mapping servlet: 'dispatcherServlet' to [/]
Thanks any help!
One of the main features of Spring Boot is autoconfiguration. The Spring Boot autoconfiguration registers and configures the DispatcherServlet automatically. Therefore, we don't need to register the DispatcherServlet manually.
You can customize Spring's DispatcherServlet by adding context parameters in the web. xml file or servlet initialization parameters. See the following table. Class that implements WebApplicationContext , which instantiates the context used by this servlet.
Please note that if you need to customize the DispatcherServlet , you can override the createDispatcherServlet() method.
The job of the DispatcherServlet is to take an incoming URI and find the right combination of handlers (generally methods on Controller classes) and views (generally JSPs) that combine to form the page or resource that's supposed to be found at that location.
I added below code into my main class, and the servlet was removed from log.
@SpringBootApplication(exclude = { DispatcherServletAutoConfiguration.class })
From Spring boot docs here
Spring Boot wants to serve all content from the root of your application
/
down. If you would rather map your own servlet to that URL you can do it, but of course you may lose some of the other Boot MVC features. To add your own servlet and map it to the root resource just declare a@Bean
of typeServlet
and give it the special bean namedispatcherServlet
(You can also create a bean of a different type with that name if you want to switch it off and not replace it).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With