gpt4 book ai didi

java - Spring AOP : @annotation(annotation)

转载 作者:塔克拉玛干 更新时间:2023-11-03 04:07:13 25 4
gpt4 key购买 nike

我(当然)正在尝试使用许多我不太了解的构造来维护一个项目。在尝试弄清楚 Spring 中 AOP 使用的过程中,我遇到了带有以下注释的方法:

@Around(value = "@annotation(注释)")

所以@Around 意味着我们正在做 AOP 中方法切入点的“周围”版本,我明白这一点。我不知道另一部分是什么意思。 Spring 文档提供了以下内容:

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

我不知道那是什么意思——“在 Spring AOP 中执行的方法”听起来像是建议的方法,但我不知道我(或 Spring)如何确定建议的方法。听起来像是具有“给定注释”的方法,但如果是这样,给出了什么注释?

此注释建议使用哪些方法?还有什么意思?

最佳答案

如果您有以下 Spring Bean:

@Component
public class foo {

@com.pkg.Bar
void fooMe() {
}
}

然后是以下建议:

@Around("@annotation(com.pkg.Bar)")

将围绕 fooMe 调用拦截器(或任何其他用 @Bar 注释的 Spring bean 方法)

@Transactional 注释就是一个很好的例子

关于java - Spring AOP : @annotation(annotation),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21588684/

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