注解aop开发步骤
1 使用@Aspect标注切面类
2 使用@通知注解标注通知方法
@Component("myAspect") @Aspect//标注当前MyAspect是一个切面类 public class MyAspect { //配置前置通知 @Before("execution(void com.zl.anno.*.*(..))") public void before() { System.out.println("前置增强...."); } public void afterReturning() { System.out.println("后置增强...."); } @Around("pointcut()") public Object around(ProceedingJoinPoint pjp) throws Throwable { System.out.println("环绕前增强...."); //切点方法 Object proceed = pjp.proceed(); System.out.println("环绕后增强...."); return proceed; } public void afterThrowing() { System.out.println("异常抛出增强...."); } @After("MyAspect.pointcut()") public void after() { System.out.println("最终增强...."); } //定义切点表达式 @Pointcut("execution(* com.zl.anno.*.*(..))") public void pointcut() {} }
3 再配置文件中配置aop自动代理<aop:aspectj-autoproxy/>
<!-- 组件扫描 --> <context:component-scan base-package="com.zl.anno"></context:component-scan> <!-- aop自动代理 --> <aop:aspectj-autoproxy></aop:aspectj-autoproxy>
标签:void,....,System,aop,println,注解,public,out From: https://www.cnblogs.com/zlyyds/p/16937962.html