美文网首页
xml和注解方式配置aop

xml和注解方式配置aop

作者: 又双叒叕苟了一天 | 来源:发表于2018-01-30 19:02 被阅读0次

xml方式

1.配置bean或者componentscan,给Aspect类加上@Component
2.配置web.xml

<aop:config>
  <aop:aspect ref="myaspect"> 
    <aop:before method="" pointcut="execution(* *..*.*(..))"/>
  </aop:aspect>
</aop:config>

注解方式

1.配置web.xml

//开启自动代理
<aop:aspectj-autoproxy/>

2.加上注解

@Component
@Aspect
public class MyAspect{
  @Pointcut(value="execution(* *..*.*(..))")
  public void fn(){}

  @Before(value="fn")
  public void before(){前置通知}
}

其余注解:After,AfterReturning,Around..
注意Around方法

public void myAround(ProceedingJoinPoint jp){
  sysout("前");
  jp.proceed();
  sysout("后");
}

相关文章

网友评论

      本文标题:xml和注解方式配置aop

      本文链接:https://www.haomeiwen.com/subject/dauczxtx.html