首页 > 编程语言 > 详细

Spring AOP 实现方法2 3 自定义方式和注解

时间:2021-04-08 18:35:52      阅读:19      评论:0      收藏:0      [点我收藏+]
二 
DiyPointCut.class
public class DiyPointCut {
    public void before(){
        System.out.println("=========在前=========");
    }
    public void after(){
        System.out.println("=========在后=========");
    }
}

<!--方式二 自定义类-->
<bean id="diy" class="com.yao.diy.DiyPointCut"></bean>
    <aop:config>
<!--自定义切面  ref要引用的类-->

<aop:aspect  ref="diy">
<!--    切入点-->
    <aop:pointcut id="point" expression="execution(* com.yao.service.userServiceImpl.*(..))"/>
<!--    通知-->
    <aop:before method="before" pointcut-ref="point"></aop:before>
    <aop:after method="after" pointcut-ref="point"></aop:after>
</aop:aspect>
    </aop:config>

三

//方式3
//使用注解方式实现 aop
@Aspect//标注这个类是个切面
public class AnnotationPointCut {
    @Before("execution(* com.yao.service.userServiceImpl.*(..))")
    public void before(){
        System.out.println("=========在前 注解方式=========");
    }
    @After("execution(* com.yao.service.userServiceImpl.*(..))")
    public void after(){
        System.out.println("=========在后  注解方式=========");
    }
}

<!--    方式3 注解-->
    <bean id="annotation" class="com.yao.diy.AnnotationPointCut"></bean>
<!--    开启注解支持-->
    <aop:aspectj-autoproxy/>

  

Spring AOP 实现方法2 3 自定义方式和注解

原文:https://www.cnblogs.com/yyyyyou/p/14631753.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!