spring__AOP 方式二: 使用自定义类实现

XML文件
<!-- 方式二:自定义类--> <bean id="diy" class="com.x.diy.DiyPointCut"/> <aop:config> <!-- 自定义切面,ref=“diy”--> <aop:aspect ref="diy"> <!-- 切入点--> <aop:pointcut id="point" expression="execution(* com.x.service.UserServiceImpl.*(..))"/> <!-- 通知--> <aop:before method="before" pointcut-ref="point"/> <aop:after method="after" pointcut-ref="point"/> </aop:aspect> </aop:config>
DiyPointCut.java

public
class DiyPointCut { public void before(){ System.out.println("方法执行前================"); } public void after(){ System.out.println("方法执行后================"); } }

 

输出结果:

 

方法执行前================
增加用户
方法执行后================

posted @ 2021-04-25 16:29  琴湖copy王  阅读(58)  评论(0)    收藏  举报