AOP 프록시와 내부 호출 문제 - 구조 변경

박찬우·2024년 2월 17일
0

스프링

목록 보기
79/88

구조 변경

  • 내부 호출이 발생하지 않도록 구조를 변경하는 것
  • 권장하는 방법

예)

  • 서비스
@Slf4j
@Component
@RequiredArgsConstructor
public class CallServiceV3 {

    private final InternalService internalService;

    public void external() {
        log.info("call external");
        internalService.internal(); //외부 메서드 호출
    }

}
@Slf4j
@Component
public class InternalService {
    public void internal() {
        log.info("call internal");
    }
}
  • 테스트
@Slf4j
@SpringBootTest
@Import(CallLogAspect.class)
class CallServiceV3Test {
    @Autowired
    CallServiceV3 callService;

    @Test
    void external() {
        callService.external();
    }
}

  • 결과
    • 이 방법도 괜찮고
    • 클라이언트에서 둘다 따로 호출하는 것도 방법이다
profile
진짜 개발자가 되어보자

0개의 댓글