***************************
APPLICATION FAILED TO START
***************************
Description:
The dependencies of some of the beans in the application context form a cycle:
┌─────┐
| securityConfig defined in file [C:\Users\dnflt\Downloads\***\***\out\production\classes\com\pyo\***\config\SecurityConfig.class]
↑ ↓
| OAuth2DetailsService defined in file [C:\Users\dnflt\Downloads\***\***\out\production\classes\com\pyo\pyostagram\config\oauth\OAuth2DetailsService.class]
└─────┘
Action:
Relying upon circular references is discouraged and they are prohibited by default. Update your application to remove the dependency cycle between beans. As a last resort, it may be possible to break the cycle automatically by setting spring.main.allow-circular-references to true.
해당 오류는 DI의 사이클 문제로
어노테이션으로 bean 등록된 어노테이션 간의 참조순환 문제입니다.
저의 경우는
@RequiredArgsConstructor
@Service
public class OAuth2DetailsService extends DefaultOAuth2UserService {
private final UserRepository userRepository;
private final BCryptPasswordEncoder bCryptPasswordEncoder;
.
.
.
.
.
.
@Override
public OAuth2User loadUser(OAuth2UserRequest userRequest) throws OAuth2AuthenticationException {
OAuth2User oauth2User = super.loadUser(userRequest);
Map<String, Object> userInfo = oauth2User.getAttributes();
String name = (String) userInfo.get("name");
String email = (String) userInfo.get("email");
String username = "facebook_" + (String) userInfo.get("id");
/*------------------------------문제발생----------------------------*/
String password = bCryptPasswordEncoder.encode(UUID.randomUUID().toString());
소셜 로그인을 구현하는 도중 SecurityConfig 에 있는
BCryptPassworEncoder를 가져오는 과정에서 오류가 발생하였는데
그 이유는
SecurityConfig의 cofigure 메소드에서 BCryptPassworEncoder를 참조하고
OAuth2DetailsService에서 BCryptPassworEncoder를 사용하기 위해
또다시 SecurityConfig를 참조하기 때문에 에러가 발생한 것입니다.
해결방법으론
application.yml
spring:
application:
name: //개인프로젝트//
main:
allow-circular-references: true
allow-circular-references 를 true로 설정하거나
@RequiredArgsConstructor
@Service
public class OAuth2DetailsService extends DefaultOAuth2UserService {
private final UserRepository userRepository;
.
.
.
.
.
.
@Override
public OAuth2User loadUser(OAuth2UserRequest userRequest) throws OAuth2AuthenticationException {
OAuth2User oauth2User = super.loadUser(userRequest);
Map<String, Object> userInfo = oauth2User.getAttributes();
String name = (String) userInfo.get("name");
String email = (String) userInfo.get("email");
String username = "facebook_" + (String) userInfo.get("id");
/*------------------------------문제해결----------------------------*/
String password = new BCryptPasswordEncoder().encode(UUID.randomUUID().toString());
BCrpytPasswordEncorder 의 의존성 주입을 없애고
따로
new 객체로 생성하여 해결.
'트러블슈팅' 카테고리의 다른 글
[오류해결] Uncaught TypeError: "" is not a function (0) | 2023.02.02 |
---|---|
Caused by: java.sql.SQLSyntaxErrorException: (conn=4200) Data too long for column 'username' at row 1 (0) | 2023.01.31 |
[ajax] ajax의 parsererror 오류 해결 : status 200 error (0) | 2023.01.29 |
[Spring] Controller 2번찍히는 현상 (0) | 2023.01.21 |
댓글 때문에 게시글이 삭제가 안될 때 (Foreign key 설정때문에) (0) | 2023.01.19 |
댓글