@WebMvcTest에서 Security Filter 제외하기 - PEACH-BROS/lets-merge GitHub Wiki

@SpringBootTest 에서 테스트의 경량화를 위해 @WebMvcTest로 변경하였다.

To test whether Spring MVC controllers are working as expected, use the @WebMvcTest annotation. @WebMvcTest auto-configures the Spring MVC infrastructure and limits scanned beans to @Controller, @ControllerAdvice, @JsonComponent, Converter, GenericConverter, Filter, HandlerInterceptor, WebMvcConfigurer, and HandlerMethodArgumentResolver. Regular @Component beans are not scanned when using this annotation.

@WebMvcTestCustomOAUth2UserService를 스캔하지않음.

@Service, @Component는 스캔 대상이 아님.

SecurityConfig를 생성하기 위한 CustomOAuth2UserService를 읽을수 없기 때문에 발생한다.

이를 위해 SecurityConfig를 컴포넌트 스캔에서 제거한다.

@WebMvcTest(value = MissionController.class, excludeFilters = {
        @ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, classes = SecurityConfig.class)
})