일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 |
Tags
- github api
- 람다식
- 스파르타코딩클럽
- raw 타입
- Study Halle
- annotation processor
- 정렬
- 함수형 인터페이스
- 로컬 클래스
- 바운디드 타입
- System.in
- public 필드
- 항해99
- 상속
- 합병 정렬
- auto.create.topics.enable
- 제네릭 와일드 카드
- System.err
- System.out
- 자바스터디
- Switch Expressions
- Java
- junit 5
- 프리미티브 타입
- 익명 클래스
- 브릿지 메소드
- 자바할래
- 제네릭 타입
- 접근지시자
- Effective JAVA
Archives
- Today
- Total
코딩하는 털보
21.11.17 TIL 본문
오늘의 삽질
순환 참조 에러 Is there an unresolvable circular reference?
UserService가 MonsterService를 DI 받고
@Service
@RequiredArgsConstructor
public class UserService {
private final UserRepository userRepository;
private final FollowServiceImpl followService;
private final MonsterService monsterService;
private final HabitServiceImpl habitService;
반대로 MonsterService도 UserService를 DI 받는다면
@Service
@RequiredArgsConstructor
public class MonsterService {
private final MonsterRepository monsterRepository;
private final MonsterDatabaseRepository monsterDatabaseRepository;
private final UserService userService;
private final MonsterCollectionService monsterCollectionService;
순환 참조로 인해 어플리케이션 빌드 시점에서 에러가 발생한다.
Setter로 의존성 주입을 받거나 @Lazy로 Lazy 초기화 방식의 주입을 사용하여 해결할 수 있지만,
스프링은 순환 참조의 고리를 끊는 것을 추천한다.
Comments