we don't reference Aspects. but define Aspect Configuration which tells when, where to apply Apsect to.
needed dependency
Anything that starts with get in a method is applied.
(..) means if there are zero or more arguments. In this way, it is possible to express where Aspect will be executed.
by defining Pointcut we don't have to repeat that @Before thing.
don't care about access modifier
don't care what method return
inside Circle class we are going to apply our advice to every method.
we can use "within" to represent same thing as above. (..) means same as above in this case it will include root package and all the subpackage
"within" is for class name , "execution" is for method name
we can also use logical operation. in this case we are trying to find getter method inside Circle class.
JointPoint is a location where advice get executed. in spring it can only be method.
by specifying argument inside advice method we can use the argument that is getting passed into target method. also telling we will apply this advice method to method which have string as argument.
there are many advice annotation @After ,@Before, @AfterReturning, @AfterThrowing....
we can use returning properties to get return value. intead of String we can get Object.
we can also get exception.
with @Around we can wrap target method , in this case it is proceedingJointPoint.proceed() is the target method
if it returns value Around Advice also need to return the value so normally we put Object on return type.
by using custom marker interface(annotation) we can specify your pointcut with our custom marker annotation.
using proxy pattern AOP can inject they're advice(method) to target method.
'WEB > Spring' 카테고리의 다른 글
스프링 핵심원리 고급편 2) ThreadLocal (0) | 2022.06.05 |
---|---|
스프링 핵심 원리 - 고급편 1) 예제만들기 (0) | 2022.01.02 |
스프링캠프 2017 Async & Spring (0) | 2021.09.10 |
김영한 (스프링 핵심원리 9) 프로토타입 스코프 - 싱글톤 빈과 함께 사용시 문제점 (0) | 2021.02.15 |
김영한 (스프링 핵심원리 8) 빈 생명주기 콜백 시작 (0) | 2021.02.14 |