一、基本配置
<aop:config>
<aop:aspect ref="operationAspect">
<aop:pointcut id="operationLogPointCut" expression="execution(* com.fan.qf.controller..*.modify*(..))"/>
<aop:around pointcut-ref="operationLogPointCut" method="doOperate"/>
</aop:aspect>
</aop:config>
其中注意配置aop注解的生命周期
<bean class="org.springframework.aop.aspectj.annotation.AnnotationAwareAspectJAutoProxyCreator" depends-on="lifecycleBeanPostProcessor"/>
我这里用到了shiro管理整个应用的生命周期,所以上面是继承了shiro生命周期
二、注解支持的配置
<aop:aspectj-autoproxy proxy-target-class="true"/>
并且是在spring扫描的一定报范围内
三、引用架包支持
就上面的配置如果没有报的支持会报错
Caused by: org.springframework.aop.framework.AopConfigException: Cannot proxy target class because CGLIB2 is not available. Add CGLIB to the class path or specify proxy interfaces.
很明显aop代理不支持cglib:
引入:
<dependency> //必须
<groupId>cglib</groupId>
<artifactId>cglib-nodep</artifactId>
<version>2.1_3</version>
</dependency>
<dependency>
<groupId>aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>1.5.0</version>
</dependency>