2 u010093674 u010093674 于 2013.07.16 10:18 提问

Spring 中的Annotation 关于@Pointcut 的问题

package com.bjsxt.aop;

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.springframework.stereotype.Component;

@Aspect
@Component
public class Inteceptor {

@Pointcut("execution(public * com.bjsxt.dao..*.*(..))")
public void myMethod(){};

@Before("myMethod()")
public void beforMethod(){
System.out.println("method starts");
}
@AfterReturning("myMethod()")
public void afteMethod(){
System.out.println("method  ends");
}

}

错误 nested exception is java.lang.IllegalArgumentException: error at

::0 can't find referenced pointcut myMethod

JDK 1.7 spring-framework-2.5.6

beans.xml:

<?xml version="1.0" encoding="UTF-8"?>
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-2.5.xsd">


2个回答

u010093674
u010093674   2013.07.16 10:21

补充一下 beans.xml是没问题的

u010751027
u010751027   2014.12.03 21:51

@Pointcut("execution(public * com.bjsxt.dao..*.*(..))") 写错了

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!