Spring boot加入一个bean以后 拦截器失效

我在config里添加了一个@Configuration的配置类,是为了给,定时任务添加一个Executor,但是加了之后,拦截器就失效了。任何请求都不走拦截器了。以下是我的代码

@Configuration
public class ApplicationContext extends WebMvcConfigurationSupport {
    @Bean
    public TaskScheduler taskScheduler(){
        return new ConcurrentTaskScheduler();
    }
}

这个是我的拦截器

public class ContextInterceptor implements HandlerInterceptor {

    public static ResourceBundle bundle;

    static {
         bundle = ResourceBundle.getBundle("application");
    }

    @Override
    public boolean preHandle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o) throws Exception {
        String staticPath = bundle.getString("sys.static.path");
        httpServletRequest.setAttribute("staticUrl",staticPath);
        String basePath = bundle.getString("sys.base.path");
        httpServletRequest.setAttribute("baseUrl",basePath);
        return true;
    }

    @Override
    public void postHandle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, ModelAndView modelAndView) throws Exception {

    }

    @Override
    public void afterCompletion(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, Exception e) throws Exception {

    }
}

求大神指教

阅读 3.2k
1 个回答

配置类不要继承 WebMvcConfigurationSupport

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题