본문 바로가기

📝 ErrorNote

[ SpringBoot / OAuth2 ] Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory. application.yml 파일 수정으로 해결

에러 내용

 

2024-03-20 13:27:21.576  WARN 92588 --- [  restartedMain] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'springSecurityFilterChain' defined in class path resource [org/springframework/security/config/annotation/web/configuration/WebSecurityConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.servlet.Filter]: Factory method 'springSecurityFilterChain' threw exception; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'org.springframework.security.oauth2.client.registration.ClientRegistrationRepository' available

 

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.

 

 

***************************
APPLICATION FAILED TO START
***************************

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.

 

 

원인 

 

에러를 발견하고 검색한 결과 

yml 파일의 띄어쓰기 문제라고 하는 경우가 많았다. 

하지만 난 아닐 거라고 생각했지만 역시다. 

 

security 아래의 user, oauth2 가 같은 라인에 있어야 했는데 oauth2 가 한칸 앞쪽에 있었다. 

 

 

해결방법

 

띄어쓰기를 잘 해주자 문제없이 실행된다. 

security:
  user:
    name: test
    password: 1234

  oauth2:
    client:
      registration:
        facebook:
          client-id: ****
          client-secret: ****
          scope:
          - public_profile
          - email