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.
-
CGLIB - 소개
CGLIB: Code Generator Library
예제 코드로 CGLIB를 간단히 이해해보자
ServiceInterface
ServiceImpl
ConcreteService
CGLIB - 예제 코드
CGLIB 코드
MethodInterceptor -CGLIB 제공
TimeMethodInterceptor
을 정의
CglibTest
CGLIB가 생성한 프록시 클래스 이름
그림으로 정리

CGLIB 제약
동작하지 않음
참고
정리 - 남은 문제
와 CGLIB가 제공하는 MethodInterceptor 를 각각 중복으로 만들어서 관리해야 할까?
프록시 팩토리 - 소개
문제점
CGLIB가 제공하는 MethodInterceptor 를 각각 중복으로 만들어서 관리해야 할까?
1. 두 기술을 함께 사용할 때 부가 기능을 적용하기 위해 JDK 동적 프록시가 제공하는 InvocationHandler와
CGLIB가 제공하는 MethodInterceptor를 각각 중복으로 따로 만들어야 할까?
InvocationHandler 나 MethodInterceptor 를 신경쓰지 않고, Advice 만 만들면 됨
1. Q: 특정 조건에 맞을 때 프록시 로직을 적용하는 기능도 공통으로 제공되었으면?
프록시 팩토리 - 예제 코드1
Advice 만들기
Advice를 만드는 방법은 여러가지지만, 기본적인 방법은 다음 인터페이스를 구현하면 됨
MethodInterceptor - 스프링이 제공하는 코드
TimeAdvice
는 MethodInvocation invocation 안에 모두 포함되어 있음
를 파라미터로 전달받기 때문
ProxyFactoryTest
기능 로직을 설정
실행 결과

프록시 팩토리를 통한 프록시 적용 확인
모두 참
인 경우 참
우 경우 참
ProxyFactoryTest - concreteProxy 추가
proxyTargetClass 옵션
ProxyFactoryTest - proxyTargetClass 추가
터페이스가 있지만 proxyTargetClass 옵션에 의해 CGLIB가 사용
프록시 팩토리의 기술 선택 방법
정리
참고
Beta Was this translation helpful? Give feedback.
All reactions