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("方法执行后================"); } }
输出结果:
方法执行前================
增加用户
方法执行后================
浙公网安备 33010602011771号