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

↘锁芯ラ 提交于 2019-12-10 11:40:22

问题


@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


回答1:


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



来源:https://stackoverflow.com/questions/51807140/what-is-the-difference-between-within-and-annotation-in-aop

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!