我在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 {
}
}
求大神指教
Spring boot加入一個bean以后 攔截器失效
慕的地8271018
2019-03-01 10:50:14