Spring Boot - HandlerInterceptor不渲染资源文件

时间:2018-06-06 10:09:05

标签: java spring spring-boot

我尝试寻找可以解决我的问题的线程。 这个对我不起作用:

Spring Boot, Java Config - No mapping found for HTTP request with URI [/...] in DispatcherServlet with name 'dispatcherServlet'

我正在使用WebSecurityConfigurerAdapterHandlerInterceptor

这是我的网络安全的内容

@Override
protected void configure(HttpSecurity http) throws Exception {
        http.csrf().disable();
        http.authorizeRequests()
            .antMatchers("/static/**"
                , "/css/**"
                , "/js/**"
                , "/scss/**"
                , "/fonts/**"
                , "/emails/**"
                , "/*.css"
                , "/*.js"
                , "/*.scss"
                , "/*.eot"
                , "/*.svg"
                , "/*.ttf"
                , "/*.woff*"
                , "/*.otf"
                , "/*.ico"
                , ForgotPasswordController.URL.FORGOT_PASS
                , ForgotPasswordController.URL.RESET_PASS
                , LoginController.URL.REGISTER
                , LoginController.URL.LOGIN
                , LoginController.URL.ROOT)
            .permitAll()
            .anyRequest()
            .access(getAllRoles())
            .and().formLogin()
            .loginPage("/login").permitAll()
            .usernameParameter("userId")
            .passwordParameter("pass")
            .failureHandler(authenticationFailureController)
            .defaultSuccessUrl("/home", true)
            .loginProcessingUrl("/login_processing").and()
            .exceptionHandling().accessDeniedPage("/access-forbidden");
  }

它运行正常,但是当我尝试添加HandlerInterceptor(用于审计跟踪目的)时,它根本不加载任何资源文件,即使我在我的websecurity配置中将permitAll()添加到这些资源文件中

这是我的处理程序拦截器:

@Service
public class OAuthSessionInterceptor implements HandlerInterceptor {
    private static final Logger logger = LoggerFactory.getLogger(OAuthSessionInterceptor.class);

    @Override
    public boolean preHandle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o) throws Exception {
        logger.error("--------- preHandle ---------");
        return true;
    }

    @Override
    public void postHandle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, ModelAndView modelAndView) throws Exception {
        logger.error("--------- postHandle ---------");
    }

    @Override
    public void afterCompletion(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, Exception e) throws Exception {
        logger.error("--------- afterCompletion ---------");
    }
}

这是它返回的内容,它为资源文件提供 404 not found

enter image description here

这是项目结构,我专注于资源部分:

enter image description here

0 个答案:

没有答案