java – 在Spring Boot上关闭DispatcherServlet

前端之家收集整理的这篇文章主要介绍了java – 在Spring Boot上关闭DispatcherServlet前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

如何在SpringBoot上禁用DispatcherServlet,即使尝试通过servlet注册禁用它,uri映射也会出现在日志中:

  1. @Bean
  2. public ServletRegistrationBean servletRegistrationBean(final DispatcherServlet dispatcherServlet) {
  3. final ServletRegistrationBean servletRegistrationBean = new ServletRegistrationBean(dispatcherServlet);
  4. servletRegistrationBean.setEnabled(false);
  5. return servletRegistrationBean;
  6. }

LOG

  1. 2015-06-10 10:39:57.552 INFO 7032 --- [ main] o.s.b.c.e.ServletRegistrationBean : Servlet dispatcherServlet was not registered (disabled)
  2. 2015-06-10 10:39:57.553 INFO 7032 --- [ main] o.s.b.c.e.ServletRegistrationBean : Mapping servlet: 'dispatcherServlet' to [/]

谢谢任何帮助!

最佳答案
我将下面的代码添加到我的主类中,并从日志中删除了servlet.

  1. @SpringBootApplication(exclude = { DispatcherServletAutoConfiguration.class })

猜你在找的Spring相关文章