1

So i'm working on spring project. I have compiled the angular project and added to spring by coping it into web-inf/static folder and registered it in spring using ResourceHandlerRegistry. I added an interceptor to interceptor HTTP requests ,but when i deployed my application the static resources stopped working as i learned that interceptor was blocking them. So i used excludePathPatterns for unblocking the static content and it worked but the interceptor stopped intercepting HTTP requests. I'm using spring 5 and wildfly 10. What can i do?

I tried adding addPathPatterns to interceptor as i know all my request will have /api/** but it didn't worked.

    @Override
        public void addResourceHandlers(ResourceHandlerRegistry registry) {
            registry.addResourceHandler("/static/**").addResourceLocations("/static/");
            registry.addResourceHandler("/assets/**").addResourceLocations("/static/assets/");
        }


    @Bean
    SessionManagementInterceptor httpApiRequestInterceptor() {
         return new SessionManagementInterceptor();
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
       // registry.addInterceptor(httpApiRequestInterceptor()).excludePathPatterns("/static/**","/assets/**");
        registry.addInterceptor(httpApiRequestInterceptor()).addPathPatterns("/api/**")
        .excludePathPatterns( new String[] {"/static/**","/assets/**"});
    }

I expected it to interceptor all request starting with /api/** and to exclude the static resources. It excluded the resources but didn't intercept api requests

  • 1
    Maybe this answer could help: https://stackoverflow.com/questions/20243130/mvc-java-config-handlerinterceptor-not-excluding-paths – sven.kwiotek Apr 24 '19 at 07:53
  • Thanks for the answer. My above code seems to be working fine. It was an uncaught exception due to which i was not getting a response on session.invalidate from interceptor. My above code works fine.. Thanks for the help mate. How do i lock this topic? – Tarunjeet Singh Salh Apr 24 '19 at 11:50

0 Answers0