Spring做面向切面功能时需要注意的异常

2 篇文章 0 订阅
2 篇文章 0 订阅

一、基本配置

     <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>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值