- 1. xml 方式配置
- <aop:config>
- <aop:aspectrefaop:aspectref="aspectDef">
- <aop:pointcutidaop:pointcutid="pointcut1"expression="execution(* com.test.spring.aop.pointcutexp..JoinPointObjP2.*(..))"/>
- <aop:before pointcut-ref="pointcut1" method="beforeAdvice" />
- </aop:aspect>
- </aop:config>
- 2. 注解方式
- @Component
- @Aspect
- public class AspectDef {
- //@Pointcut("execution(* com.test.spring.aop.pointcutexp..JoinPointObjP2.*(..))")
- //@Pointcut("within(com.test.spring.aop.pointcutexp..*)")
- //@Pointcut("this(com.test.spring.aop.pointcutexp.Intf)")
- //@Pointcut("target(com.test.spring.aop.pointcutexp.Intf)")
- //@Pointcut("@within(org.springframework.transaction.annotation.Transactional)")
- //@Pointcut("@annotation(org.springframework.transaction.annotation.Transactional)")
- @Pointcut("args(String)")
- public void pointcut1() {
- }
- @Before(value = "pointcut1()")
- public void beforeAdvice() {
- System.out.println("pointcut1 @Before...");
- }
AOP注解
最新推荐文章于 2022-11-25 23:21:14 发布
本文介绍了两种实现面向切面编程(AOP)的方法:XML配置和注解方式。通过具体的示例代码展示了如何定义切入点(pointcut)、前置通知(before advice)等关键概念。
4592

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



