본문 바로가기

개발공부/Error Handling

Spring Security 'ClientRegistrationRepository' that could not be found. 해결

카카오 소셜 로그인을 구현하고 테스트를 하기 위해 application을  실행했는데 실행이 안되고 이런 오류 메시지만 떴다. 내가 나중에 다시 참고하거나 다른 사람들에게 오류 해결 공유를 위해 간단히 정리했다.

 

에러 메시지 출력 상황

Description:

Method springSecurityFilterChain in org.springframework.security.config.annotation.web.configuration.WebSecurityConfiguration required a bean of type 'org.springframework.security.oauth2.client.registration.ClientRegistrationRepository' that could not be found.


Action:

Consider defining a bean of type 'org.springframework.security.oauth2.client.registration.ClientRegistrationRepository' in your configuration.

 

해결 방법:

application.yml 파일에서 security.oauth2...관련 내용들이 가장 아래에 있었는데 순서를 가장 위로 조정했다. 그랬더니 실행이 잘됐다.

 

검색했을 때 나온 방법들은 내 상황과 맞지 않는 방법이었다. 그러다가 한 번 SecurityConfig에 ClientRegistrationRepository를 주입하고 config에 추가했는데 그래도 해결이 안됐다.. 혼자 머리 싸매고 고민하고 있다가 문득 생각난게 yml 파일의 내용 순서를 바꿔보자 였는데 이 방법이 맞았다...! 전에 build.gradle 파일에서나 yml 파일에서 다른 오류가 발생했었을 때 순서를 바꿔서 해결했던 경험이 떠올라서 시도해봤는데 해결이 됐다.

client-id와 redirect-uri는 각자 주어진 값과 설정한 값을 넣으면 된다.