1、maven依赖:
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>1.8.1</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>1.8.1</version> <scope>runtime</scope>
</dependency>
2、类注解:
@Component,@Aspect,@EnableAspectjAutoProxy(proxyTargetClass=true)
3、方法注解:
@Around("@annotation(xxxxx) || @with(yyyyy)")
实现以上功能,还有一个比较麻烦的方法是,使用spring的BeanRegistryPostProcessor通过ApplicationContext.getByAnnotation找到所有的类,见前面的文章
本文介绍了如何在Spring中集成AspectJ进行面向切面编程,包括添加Maven依赖、使用@Component、@Aspect和@EnableAspectjAutoProxy注解,以及@Around方法注解来拦截特定注解的方法。此外,还提到了通过BeanRegistryPostProcessor查找带有特定注解的类的高级用法。
8648

被折叠的 条评论
为什么被折叠?



