java – 在Spring Boot上关闭DispatcherServlet

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

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

@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 [/]

谢谢任何帮助!

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

@SpringBootApplication(exclude = { DispatcherServletAutoConfiguration.class })
原文链接:https://www.f2er.com/spring/432011.html

猜你在找的Spring相关文章