JoJun's
Jun's Devlog
JoJun's
전체 방문자
오늘
어제
  • 분류 전체보기 (51)
    • Java (16)
      • SpringBoot (12)
      • Java (4)
    • Linux (11)
      • CentOS (4)
      • 명령어(CentOS) (5)
      • Docker (2)
    • DataBase (15)
      • 튜닝 기법 (1)
      • MSSQL (7)
      • SQLD,SQLP (6)
    • 알고리즘 (4)
      • 정렬 (1)
      • 해시 (1)
      • 완전탐색 (1)
      • 탐욕법 (1)
    • 인프라 (3)
    • Web (2)
    • 개인공간 (0)

블로그 메뉴

  • 홈

공지사항

인기 글

태그

  • log4j2
  • 알고리즘
  • Java
  • MSSQL
  • 파일그룹
  • @Component
  • docker
  • cors
  • Dockerfile
  • springboot

최근 댓글

최근 글

티스토리

hELLO · Designed By 정상우.
JoJun's
Java/SpringBoot

[SpringBoot] 종속성 순환 에러 트러블슈팅

[SpringBoot] 종속성 순환 에러 트러블슈팅
Java/SpringBoot

[SpringBoot] 종속성 순환 에러 트러블슈팅

2021. 12. 30. 16:42
728x90
반응형

AOP (Aspect Oriented Programming)를 공부하다가 "종속성 순환 에러"가 발생하였다.

해당 이슈에 대해 슈팅해보겠다.


● 트러블 이슈

각 메서드 ( Controller, Service, Repository )에서 처리 시간을 처리하는 AOP를 만드는 도중 아래 에러 메시지가 발생하였다.

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

   memberController defined in file [C:\Users\pc\Desktop\hello-spring\hello-spring\out\production\classes\hello\hellospring\controller\MemberController.class]
      ↓
   memberService defined in class path resource [hello/hellospring/SpringConfig.class]
┌─────┐
|  timeTraceAop defined in class path resource [hello/hellospring/SpringConfig.class]
└─────┘

애플리케이션 콘텍스트에서 일부 Bean의 종속성은 순환을 형성합니다.라는 에러 메시지였고,
timeTraceAop 객체가 계속 순환을 형성하고 있다.


● 분석

TImeTraceAop 객체를 살펴보자

package hello.hellospring.aop;

import org.aspectj.lang.ProceedingJoinPoint;  
import org.aspectj.lang.annotation.Around;  
import org.aspectj.lang.annotation.Aspect;

@Aspect  
public class TimeTraceAop {  
	@Around("execution(\* hello.hellospring..\*(..))")  
	public Object execute(ProceedingJoinPoint joinPoint) throws Throwable {  
		long start = System.currentTimeMillis();
	
		System.out.println("START: " + joinPoint.toString());

		try{
			return joinPoint.proceed();
		}finally {
			long finish = System.currentTimeMillis();
			long timeMs = finish - start;
			
			System.out.println("END: " + joinPoint.toString() + " "+ timeMs + "ms");
		}
	}
}

 

TimeTraceAop객체의 패키지 경로를 보면 package hello.hellospring.aop;이며
Around execution 전략에 포함되는 패키지 경로를 가지고 있다.



● 원인

TimeTraceAop의 execution 함수가 자신의 execution메소드에도 실행이 되어 계속 순환이 됨.



● 해결


public class TimeTraceAop {
    @Around("execution(* hello.hellospring..*(..)) && !target(hello.hellospring.SpringConfig)")
    public Object execute(ProceedingJoinPoint joinPoint) throws Throwable{

SpringConfig에서 TimeTraceAop를 Bean등록을 해주고 있다. execution에 hello.hellospring.SpringConfig 경로를 제외시켜줌으로써 해결했다.

728x90
반응형
저작자표시 비영리 변경금지 (새창열림)

'Java > SpringBoot' 카테고리의 다른 글

[SpringBoot] Log4j2 기본 사용법  (0) 2022.03.07
[SpringBoot] SOP, CORS 이야기  (0) 2022.02.03
[SpringBoot] Security 인증 절차 시 DB Access 여러번 일어나는 이슈.  (0) 2022.01.12
[SpringBoot] UserDetailsService UserNotFoundException 안되는 이유  (0) 2022.01.11
[SpringBoot] StereoType, @Component과 @Bean 차이점  (0) 2021.12.30
  • ● 트러블 이슈
  • ● 분석
  • ● 원인
  • ● 해결
'Java/SpringBoot' 카테고리의 다른 글
  • [SpringBoot] SOP, CORS 이야기
  • [SpringBoot] Security 인증 절차 시 DB Access 여러번 일어나는 이슈.
  • [SpringBoot] UserDetailsService UserNotFoundException 안되는 이유
  • [SpringBoot] StereoType, @Component과 @Bean 차이점
JoJun's
JoJun's
JoJun's의 기술블로그

티스토리툴바

단축키

내 블로그

내 블로그 - 관리자 홈 전환
Q
Q
새 글 쓰기
W
W

블로그 게시글

글 수정 (권한 있는 경우)
E
E
댓글 영역으로 이동
C
C

모든 영역

이 페이지의 URL 복사
S
S
맨 위로 이동
T
T
티스토리 홈 이동
H
H
단축키 안내
Shift + /
⇧ + /

* 단축키는 한글/영문 대소문자로 이용 가능하며, 티스토리 기본 도메인에서만 동작합니다.