Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what is the difference between @within and @annotation in AOP

@within

This PCD limits matching to join points within types that have the given annotation:

@Pointcut("@within(org.springframework.stereotype.Repository)")

@annotation

This PCD limits matching to join points where the subject of the join point has the given annotation. For example we may create a @Loggable annotation:

@Pointcut("@annotation(org.baeldung.aop.annotations.Loggable)")
public void loggableMethods() {}

So does it mean that @annotation only applies for user defined or custom annotations. and @within for Standard Annotatios

like image 618
sachin sarangamath Avatar asked Oct 22 '25 01:10

sachin sarangamath


1 Answers

This might be an older question, but just wanted to add the answer for more visibility.

It is as JBNizet stated in the comment, the javadoc provides a clear difference between the two:

@within: Limits matching to join points within types that have the given annotation (the execution of methods declared in types with the given annotation when using Spring AOP).

@annotation: Limits matching to join points where the subject of the join point (the method being executed in Spring AOP) has the given annotation.

from https://docs.spring.io/spring/docs/current/spring-framework-reference/core.html#aop-pointcuts-designators

like image 179
Dragos Geornoiu Avatar answered Oct 25 '25 01:10

Dragos Geornoiu



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!