小编bep*_*bep的帖子

如何配置默认的 DispatcherServlet?

throwExceptionIfNoHandlerFoundDispatcherServlet在 Spring 4.0 中引入。

我试图弄清楚如何在DispatcherServletSpring Boot 提供的自动配置中设置这个属性,但没有运气。

一些挖掘表明下面的代码段应该有效,但事实并非如此。

@Bean
public ServletContextInitializer servletContextInitializer() {
    return new ServletContextInitializer() {
        @Override
        public void onStartup(ServletContext servletContext) throws ServletException {
            servletContext.setInitParameter("throwExceptionIfNoHandlerFound", "true");

        }
    };
}  
Run Code Online (Sandbox Code Playgroud)

spring-boot

2
推荐指数
1
解决办法
5427
查看次数

标签 统计

spring-boot ×1