Skip to content

Instantly share code, notes, and snippets.

@rolroralra
Last active July 15, 2022 11:54
Show Gist options
  • Save rolroralra/b4754d16da4f7c96a5333fa7756f366c to your computer and use it in GitHub Desktop.
Save rolroralra/b4754d16da4f7c96a5333fa7756f366c to your computer and use it in GitHub Desktop.
AOP (Aspect Oritented Programming)

Pointcut designators (execution, this, target, within, args) in Spring AOP

https://tedblob.com/pointcut-designators-of-spring-aop/#:~:text=Args%20limits%20matching%20to%20join,instances%20of%20the%20given%20types.&text=This%20expression%20matches%20the%20methods,passed%20at%20runtime%20is%20Serializable.


JoinPoint - Target, This, Args, Kind, Signature, StaticPart

  • getArgs

the method arguments

  • getThis

the proxy object. This will always be the same object as that matched by the this pointcut designator.

  • getTarget

the target object. This will always be the same object as that matched by the target pointcut designator.

  • getSignature

a description of the target method that is being advised

  • toString

a useful description of the target method being advised

  • getKind

Kind of Join point. In Spring, it is always of kind “method-execution” as we support advice only for method execution

@Component
@Aspect
public class LoggingAspect {
    @Before("execution(* com..Utility.formatData(..))")
    public void beforeAdviceMethod(JoinPoint joinPoint) {
        System.out.println("beforeAdviceMethod <- start");
        System.out.println("Join Point static part = " + joinPoint.getStaticPart());
        System.out.println("Signature = " + joinPoint.getSignature());
        System.out.println("Args = " + Arrays.toString(joinPoint.getArgs()));
        System.out.println("Kind = " + joinPoint.getKind());
        System.out.println("Join Point Long String " + joinPoint.toLongString());
        System.out.println("Join Point Short String " + joinPoint.toShortString());
        System.out.println("Join Point String " + joinPoint.toString());
        System.out.println("Join Point getTarget " + joinPoint.getTarget());
        System.out.println("Join Point getThis " + joinPoint.getThis());
        System.out.println("beforeAdviceMethod <- stop\n\n");
    }
}
        // calling the target method
        Utility utility = context.getBean(Utility.class);
        utility.formatData("John", "Doe");
  • output
beforeAdviceMethod <- start
Join Point static part = execution(String com.tedblob.Utility.formatData(String,String))
Signature = String com.tedblob.Utility.formatData(String,String)
Args = [John, Doe]
Kind = method-execution
Join Point Long String execution(public java.lang.String com.tedblob.Utility.formatData(java.lang.String,java.lang.String))
Join Point Short String execution(HelloBean.formatData(..))
Join Point String execution(String com.tedblob.Utility.formatData(String,String))
Join Point getTarget com.tedblob.Utility@6b695b06
Join Point getThis com.tedblob.Utility@6b695b06
beforeAdviceMethod <- stop

CGLib (Code Generator Library) in Java

https://nhj12311.tistory.com/469

https://nhj12311.tistory.com/469


Spring AOP vs AspectJ

https://logical-code.tistory.com/118

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment