我如何在SpringBoot上禁用DispatcherServlet,甚至尝试通过Servlet注册禁用它,uri映射也会出现在日志中:
@Bean
public ServletRegistrationBean servletRegistrationBean(final DispatcherServlet dispatcherServlet) {
final ServletRegistrationBean servletRegistrationBean = new ServletRegistrationBean(dispatcherServlet);
servletRegistrationBean.setEnabled(false);
return servletRegistrationBean;
}
日志
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 [/]
谢谢你的帮助!
最佳答案
我在主类中添加了以下代码,并且该servlet已从日志中删除。
@SpringBootApplication(exclude = { DispatcherServletAutoConfiguration.class })