You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
JDK 동적 프록시 - 소개
주의
기본 예제 코드
AInterface
AImpl
BInterface
BImpl
JDK 동적 프록시 - 예제 코드
JDK 동적 프록시 InvocationHandler
JDK 동적 프록시가 제공하는 InvocationHandler
제공되는 파라미터는 다음과 같음
TimeInvocationHandler
TimeInvocationHandler 내부 동작
proxy.call()
↓
invoke(proxy, method, args)
↓
공통 로직 (시간 측정)
↓
method.invoke(target, args) → 진짜 객체의 메서드 실행
↓
공통 로직 (시간 측정 종료 + 로그)
↓
결과 리턴
JdkDynamicProxyTest
동적 프록시를 생성하그결과를 반환
생성된 JDK 동적 프록시
실행 순서
동적 프록시 클래스 정보
dynamicA() 와 dynamicB() 둘을 동시에 함께 실행하면 JDK 동적 프록시가 각각 다른 동적 프록시 클래스를 만
들어주는 것을 확인 가능
정리
InvocationHandler하나만 만들어서 처리하면 끝JDK 동적 프록시 도입 후

JDK 동적 프록시 - 적용1
LogTraceBasicHandler
DynamicProxyBasicConfig
Service , Repository 에 맞는 동적 프록시를 생성해주면 됨
시는 모두 LogTraceBasicHandler 를 사용
ProxyApplication - 수정
남은 문제
=> no-log를 실행해도 동적 프록시가 적용되고, LogTraceBasicHandler가 실행되기 떄문에 로그가 남음, 이 부분을 로그가 남지 않도록 처리해야 함
JDK 동적 프록시 - 적용2
LogTraceFilterHandler
xxx : xxx가 정확히 매칭되면 참
xxx* : xxx로 시작하면 참
*xxx : xxx로 끝나면 참
xxx : xxx가 있으면 참
DynamicProxyFilterConfig
ProxyApplication - 추가
JDK 동적 프록시 - 한계
그렇다면 V2 애플리케이션 처럼 인터페이스 없이 클래스만 있는 경우에는 어떻게 동적 프록시를 적용할 수 있을까?
이것은 일반적인 방법으로는 어렵고 CGLIB 라는 바이트코드를 조작하는 특별한 라이브러리를 사용해야 함
All reactions