AOP 프록시 기술과 한계 - 의존관계 주입

박찬우·2024년 2월 17일
0

스프링

목록 보기
81/88

의존관계 주입

  • JDK 동적 프록시를 구체 클래스 타입에 주입
  • CGLIB 프록시를 구체 클래스 타입에 주입

예)

@Slf4j
@SpringBootTest(properties = {"spring.aop.proxy-target-class=false"}) //JDK 동적프록시, DI 예외 발생
//@SpringBootTest(properties = {"spring.aop.proxy-target-class=true"}) //CGLIB 프록시, 성공
@Import(ProxyDITest.class)
public class ProxyDITest {
    @Autowired
    MemberService memberService; //JDK 동적 프록시 OK, CGLIB OK

    @Autowired
    MemberServiceImpl memberServiceImpl; //JDK 동적 프록시 X, CGLIB OK

    @Test
    void go() {
        log.info("memberService class={}", memberService.getClass());
        log.info("memberServiceImpl class={}", memberServiceImpl.getClass());
        memberServiceImpl.hello("hello");
    }
}
profile
진짜 개발자가 되어보자

0개의 댓글