二
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/>
原文:https://www.cnblogs.com/yyyyyou/p/14631753.html