AOP中@within和@annotation有什么区别

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

@内

此 PCD 将匹配限制为具有给定注释的类型内的连接点:

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

@annotation

此 PCD 将匹配限制为连接点的主题具有给定注释的连接点。例如我们可以创建一个@Loggable 注释:

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

这是否意味着@annotation 仅适用于用户定义或自定义注释。 和 @within 用于标准注释

这可能是一个较旧的问题,但只是想添加答案以提高可见度。

如评论中JBNizet所述,javadoc提供了两者之间的明显区别:

@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.

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