WEB/Spring

[java brains , spring docs] Aspect Oriented Progamming

Tony Lim 2021. 10. 13. 18:29
728x90

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.

 

 

 

 

 

 

 

728x90