gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 14:22:52 25 4
gpt4 key购买 nike

@内

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

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

@注解

此 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

关于spring - AOP中@within和@annotation有什么区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51807140/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com