码迷,mamicode.com
首页 > 编程语言 > 详细

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

时间:2016-10-13 15:04:44      阅读:341      评论:0      收藏:0      [点我收藏+]

标签:

【说明】

  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>    

 

  

 

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

标签:

原文地址:http://www.cnblogs.com/15ho/p/5956121.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!