본문 바로가기
Spring/공부 & 트러블 슈팅

빈 순환 참조 발생 (The dependencies of some of the beans in the application context form a cycle)

by 정구정구 2026. 7. 7.

 양방향 매핑을 구현하는 과정에서 아래와 같은 에러가 발생했다.

2026-07-07T15:54:13.312+09:00 ERROR 5692 --- [Schedule2Project] [           main] o.s.b.d.LoggingFailureAnalysisReporter   : 

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

Description:

The dependencies of some of the beans in the application context form a cycle:

   commentController defined in file [D:\workspace\Schedule2Project\build\classes\java\main\com\example\schedule2project\comment\controller\CommentController.class]
┌─────┐
|  commentService defined in file [D:\workspace\Schedule2Project\build\classes\java\main\com\example\schedule2project\comment\service\CommentService.class]
└─────┘

 

 원인을 찾아보니까 A 클래스를 생성하기 위해서 B를 주입해야하고, B를 생성하기 위해서 A를 주입해야하는 상황에서 발생해서 무한 참조가 발생했다는 내용이다.

 근데 로그에 뜬 순환 사이클이 좀 이상하다. 왜 한 클래스에서 순환이 발생하지? 

 

트러블 슈팅

 

바로 한 Service 클래스에 자기 자신을 주입하려 했기 때문! 

 

무아지경으로 코딩하다가 보니 CommentService에서 CommentService를 선언해놨다. 이를 제거하니 정상적으로 서버가 올라온 것을 확인 할 수 있었다. 

 

별 것 아닌 실수였고, 간단히 해결된 이슈였지만, 의존성 계층을 잘 설계해야 하겠다는 경각심을 가지게 되었다.