报错原因如下:
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
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
解决方案 »
- 异常求分析,急急急!在线等,在线结账
- hibernate对mysql分页
- 【高分求救】http的返回状态或者内容能否自定义?
- 100分求解xfire无法调用VC 使用soap toolkit 3.0 生成的wsdl的问题
- DiskFileUpload获取不了请求的文件
- jsp程序发布到tomcat服务器为什么找不到sqlserver驱动程序.
- 请帮忙看看我的access为何连接不上!!
- 启动j2ee,提示信息如下,请问C:\j2sdkee1.3\bin>j2ee -verbose
- 是不是表单页面jsp传到后台的数据都是字符串类型啊 springmvc怎么处理时间类型啊
- 开发环境
- servlet 下载Excel输出流,输出流已实现就是不知道怎么下载,并提升保存
- java调用.net webService问题
我一般Advice和Aspect都是分开写的。