실행 시간을 측정하는 TimeTraceAop 클래스를 만들었더니 스프링부트 순환참조 에러메세지가 떴다.
Description:
The dependencies of some of the beans in the application context form a cycle:
memberController
↓
memberService defined in class path resource [hello/hellospring/SpringConfig.class]
┌─────┐
| timeTraceAop defined in class path resource [hello/hellospring/SpringConfig.class]
└─────┘
Action:
Despite circular references being allowed, the dependency cycle between beans could not be broken. Update your application to remove the dependency cycle.
(구글번역돌림)
애플리케이션 컨텍스트에 있는 일부 Bean의 종속성은 순환을 형성합니다.
행동: 순환 참조가 허용됨에도 불구하고 Bean 간의 종속성 순환은 깨질 수 없습니다. 종속성 주기를 제거하려면 애플리케이션을 업데이트하세요.
구글링해보니까 다른 사람들은 저 네모(순환빈)이 2개던데 난 왜 1개지.. 1개인데 왜 순환하지..안에서 갖다쓰는거 없는것같은데..
package hello.hellospring.aop;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;
@Aspect
@Component
public class TimeTraceAop {
@Around("execution(* hello.hellospring..*(..))")
public Object execute(ProceedingJoinPoint joinpoint) throws Throwable {
long start = System.currentTimeMillis();
System.out.println("START: "+joinpoint.toString()+" ms");
try {
return joinpoint.proceed();
} finally {
long finish = System.currentTimeMillis();
long timeMs = finish-start;
System.out.println("END: "+joinpoint.toString()+" "+timeMs+" ms");
}
}
}
AOP(TimeTraceAop)를 @Component 로 선언 vs SpringConfig에 @Bean으로 등록 - 인프런
안녕하세요. 김영한 팀장님,AOP(TimeTraceAop)를 @Component로 선언하지 않고SpringConfig에 @Bean으로 등록할 수 있다고 설명하셨는데 실제로 코드를 돌려보면 빈 순환 참조 에러가 발생합니다.강의대로 @Com
www.inflearn.com
빈도 설정하고 컴포넌트도 설정해서 오류가 생긴 것 같다. 해결완료!
'Language > Spring Boot || Spring' 카테고리의 다른 글
스프링 빈 스코프 (1) | 2024.02.18 |
---|---|
Spring Boot에서 base64로 이미지 업로드,다운로드 기능 구현하기 (0) | 2024.02.17 |
Spring 빈의 생명주기와 생명주기 콜백에 대해 알아보자 (0) | 2024.02.15 |
Spring 생성자 주입을 선택해야 하는 이유 (0) | 2024.02.08 |
Spring 의존관계 주입(DI) 방법 (0) | 2024.02.07 |