报错原因如下:
nested exception is java.lang.IllegalArgumentException: error at ::0 can't find referenced pointcut anyMethod  代码如下:
@Repository
@Aspect
public class MyInterceptor {
@Pointcut("execution (* com.wukong.service.impl.PersonServiceBean.*(..))")
private void anyMethod() {}//声明一个切入点

@Before("anyMethod()")
// @Before("execution (* com.wukong.service.impl.PersonServiceBean.*(..))")
public void doAccessCheck(){
System.out.println("前置通知");
}
}package com.wukong.service.impl;import java.util.jar.Attributes.Name;import org.springframework.stereotype.Repository;
import org.springframework.stereotype.Service;import com.wukong.service.PersonService;
@Repository
public class PersonServiceBean implements PersonService {
private String name;
@Override
public void save(String name) {
System.out.println("我是save()方法");
} @Override
public void update(String name, Integer id) {
System.out.println("我是update()方法");
} @Override
public String getPersonName(Integer id) {
return "xxx";
} public PersonServiceBean(String name) {
super();
this.name = name;
} public PersonServiceBean() {
super();
}}
package junit.test;import static org.junit.Assert.*;import org.junit.BeforeClass;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;import com.wukong.service.PersonService;public class Interceptor { @BeforeClass
public static void setUpBeforeClass() throws Exception {
} @Test public void interceptorTest(){
ApplicationContext ctx = new ClassPathXmlApplicationContext("beans.xml");
PersonService personService = (PersonService)ctx.getBean("personServiceBean");
// MyInterceptor myInterceptor = (MyInterceptor)ctx.getBean("myInterceptor"); personService.save("xxx");
}
}
问题是: 这样写就会报错
public class MyInterceptor {
@Pointcut("execution (* com.wukong.service.impl.PersonServiceBean.*(..))")
private void anyMethod() {}//声明一个切入点

@Before("anyMethod()")
// @Before("execution (* com.wukong.service.impl.PersonServiceBean.*(..))")
public void doAccessCheck(){
System.out.println("前置通知");
}
}
但是如果这样写就能正常运行:
public class MyInterceptor {
/*@Pointcut("execution (* com.wukong.service.impl.PersonServiceBean.*(..))")
private void anyMethod() {}//声明一个切入点

@Before("anyMethod()")*/
@Before("execution (* com.wukong.service.impl.PersonServiceBean.*(..))")
public void doAccessCheck(){
System.out.println("前置通知");
}
}求大神们解惑这是为什么呢?
百度到很多说只要更改aspectj.jar就行,但是都试过了都不行
菜鸟求解惑javaEE Spring AOP