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

查看:136
本文介绍了java - 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 {

    }
}

求大神指教

解决方案

配置类不要继承 WebMvcConfigurationSupport

这篇关于java - Spring boot加入一个bean以后 拦截器失效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆