PROGRAMMING/JAVA

Spring Boot Interceptor를 특정 URL에 적용 방법

OJR 2023. 4. 3. 02:26

 

 

@Configuration
public class WebConfig implements WebMvcConfigurer {
    
    @Autowired
    private MyInterceptor myInterceptor;
    
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(myInterceptor)
            .addPathPatterns("/specific-url/**");
    }
}

 

addPathPatterns() 메서드는 인터셉터가 /specific-url/로 시작하는 URL에만 적용되도록 지정하는 데 사용

 

반대로, 특정 URL을 제외해야 하는 경우 유사한 방식으로 excludePathPatterns() 메서드를 사용

반응형