springAOP注解方式定义切入点报错error at ::0 can't find referenced pointcut

【说明】

  1、使用spring版本:4.0.4

  2、springAOP相关依赖包:

    1)aopalliance-1.0.jar

    2)aspectjweaver-1.8.9.jar

    3)aspectjrt-1.8.9.jar

  3、分析:

    1)当切面类的方法上通知注解直接输入切入点表达式时,没有报错。切面类代码如下:

import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.hibernate.Transaction;
import org.springframework.stereotype.Component;

@Component("myTransaction")
@Aspect
public class MyTransaction extends HibernateUtil{
    
    private Transaction transaction;

    @Before("execution(* net.fifteenho.spring.aop.annotation.PersonDaoImpl.*(..))")
    public void beginTransaction() {
        transaction = sessionFactory.getCurrentSession().beginTransaction();
    }
    
    @AfterReturning("execution(* net.fifteenho.spring.aop.annotation.PersonDaoImpl.*(..))")
    public void commit() {
        transaction.commit();
    }
}

    2)当切面类的方法上通知注解引入定义的切入点,报错error at ::0 can't find referenced pointcut。切面类代码如下:

import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.hibernate.Transaction;
import org.springframework.stereotype.Component;

@Component("myTransaction")
@Aspect
public class MyTransaction extends HibernateUtil{
    
    @Pointcut("execution(* net.fifteenho.spring.aop.annotation.PersonDaoImpl.*(..))")
    private void mypc(){}
    
    private Transaction transaction;

    @Before("mypc()")
    public void beginTransaction() {
        transaction = sessionFactory.getCurrentSession().beginTransaction();
    }
    
    @AfterReturning("mypc()")
    public void commit() {
        transaction.commit();
    }
}

 

  4、本人解决方法:aspectjweaver.jar替换较新的aspectjweaver-1.8.9.jar

  5、报错原因:springAOP依赖jar版本过低。

 

【springAOP相关依赖包下载maven】

    <!-- https://mvnrepository.com/artifact/aopalliance/aopalliance -->
    <dependency>
        <groupId>aopalliance</groupId>
        <artifactId>aopalliance</artifactId>
        <version>1.0</version>
    </dependency>

    <!-- https://mvnrepository.com/artifact/org.aspectj/aspectjweaver -->
    <dependency>
        <groupId>org.aspectj</groupId>
        <artifactId>aspectjweaver</artifactId>
        <version>1.8.9</version>
    </dependency>


    <!-- https://mvnrepository.com/artifact/org.aspectj/aspectjrt -->
    <dependency>
        <groupId>org.aspectj</groupId>
        <artifactId>aspectjrt</artifactId>
        <version>1.8.9</version>
    </dependency>    

 

  

 

转载于:https://www.cnblogs.com/15ho/p/5956121.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值