카테고리 없음
Spring-aop
트밀
2022. 12. 29. 00:02
목차
aop를 구현하는 방식은 크게 2가지이고 세부적으로는 3가지.
1. 컴파일위빙
(1) aspectJ(리플렉션)기반.
조금 더 고급기능들이 들어있고, 메서드가 몇백만번 쓰인다면, 이것이 성능면으로 더 좋기에 추천. 하지만 실무에서 다루는 일은 거의 없다.
ex) spring-aspects package(cache,scheduling,transaction,beans-factory)
2. 런타임위빙
spring-cglib package -
(2)dynamic proxy(자바기본리플렉션기능)
인터페이스대상
-java.lang.reflect.Proxy( since java 1.3)
Most Used Methods.
- newProxyInstance()
Returns an instance of the dynamically built class for the specified interfaces. Method invocations - getInvocationHandler()
Returns the invocation handler of the specified proxy instance. - isProxyClass()
Indicates whether or not the specified class is a dynamically generated proxy class. - getProxyClass()
Returns the dynamically built Class for the specified interfaces. Creates a new Class when necessary - generateProxy()
_newProxyInstance
(3)cglib
클래스 대상.
바이트코드생성.
내부적으로 asm이쓰임, 비슷한 라이브러리로는 Javaassist(히카리에서 많이쓰임)가 있습니다.