본문 바로가기

Back-End/SpringBoot

[SpringBoot] 잘 되던 인터셉터가 동작이 안 될 때, 인터셉터 등록 방법 변경

로컬에서는 잘 작동하던 인터셉터가 배포 후에는 작동이 안 되는 게 확인되었습니다.

인터셉터 등록 조차 되지 않아서 인터셉터 등록 방식을 변경했습니다. 원인은 모르겠습니다..

기존 인터셉터 등록 방식

@Configuration
public class CustomWebConfig extends WebMvcConfigurationSupport {

    @Override
    protected void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new UserHandlerInterceptor());
    }
}

 

변경 후

@Configuration
public class CustomWebConfig {

    @Bean
    public MappedInterceptor addInterceptors() {
        return new MappedInterceptor(new String[]{"/**"}, new UserHandlerInterceptor());
    }
}

 

참고

https://stackoverflow.com/questions/22633800/spring-mvc-interceptor-never-called

 

Spring MVC - Interceptor never called

I am trying to configure an interceptor in my application and I am not being able to make it work. In my application configuration class, I have configured in the following way: @Configuration @

stackoverflow.com