상세 컨텐츠

본문 제목

@WebMvcTest에서 CustomOAuth2UserService을 찾을 수 없음

개인 공부/TDD

by 카페코더 2020. 6. 29. 17:39

본문

반응형

No qualifying bean of type "aa.aaa.aaa.aaa.CustomOAuth2UserService" 메시지가 출력된다.

@WebMvcTest는 CustomOAuth2UserService를 스캔하지 않기 때문이다.

@WebMvcTest는 WebSecurityCOnfigurerAdapter, WebMvcConfigurer를 비롯한 @ControllerAdvice, @Controller를 읽는다. 즉, @Repository, @Service, @Component는 스캔 대상이 아니란 의미다

따라서 SecurityConfig는 읽었지만, SecurityConfig를 생성하기 위해 필요한 CustomOAuth2UserService는 읽을수 없어 앞에서와 같이 에러가 발생한다.

 

해결 방법으로, 스캔 대상에서 SecurityConfig를 제거한다.

@WebMvcTest(controllers = HelloController.class, excludeFilters = {
        @ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, classes = SecurityConfig.class)
})
반응형

관련글 더보기

GitHub 댓글

댓글 영역