问题描述
- 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">
解决方案
补充一下 beans.xml是没问题的
解决方案二:
@Pointcut("execution(public * com.bjsxt.dao..*.*(..))") 写错了