Spring AOP 中 @within 和 @annotation 有啥区别?

2017 年 5 月 8 日
 esolve

例如 @within(org.springframework.transaction.annotation.Transactional) 和 @annotation(org.springframework.transaction.annotation.Transactional)

感觉是一个意思?

4908 次点击
所在节点    Java
6 条回复
springmarker
2017 年 5 月 8 日
within(com.common.xxx*) && @annotation(hello)
指定 com.common.xxx 目录下及其所有子目录下的所有带有 @hello 注解的方法体为切点。
esolve
2017 年 5 月 8 日
@springmarker

这里说的是 @within
不是 within
justicelove
2017 年 5 月 8 日
spring aop 使用的是 aspectj 的注解,可以百度下 aspectj
springmarker
2017 年 5 月 8 日
哦抱歉,看错了,文档的意思是 一个是对象级别的,一个是方法级别的。
注解写在方法上,@within 的是不会执行的,@annotation 的会执行,反之亦然
esolve
2017 年 5 月 8 日
@springmarker

以下面连个为例

@within(org.springframework.transaction.annotation.Transactional) 和 @annotation(org.springframework.transaction.annotation.Transactional)

如果是 @annotation 的话,意思是对方法实施事务
但是如果是 @within 的话,是啥意思?
springmarker
2017 年 5 月 8 日
你写个例子不就好了,分别在方法和类上加注解,再看用 @within 和 @annotation 有什么区别,几分钟的事情,比我在这跟跟你讲理解的快得多。

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/359900

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX