Spring的AOP常见错误(顶)
来源:互联网 发布:法律大数据解决方案 编辑:程序博客网 时间:2024/05/18 14:42
Spring的AOP常见错误
在学习AOP的时候,遇到错误是在所难免的,当在google中搜索这些错误的时候,发现很多人都是没有仔细推敲,只是人云亦云。这里把遇到的一些错误总结下来,以便以后查阅。
1. 切入点表达式定义错误
[1] 错误详细信息如下,红色标注是错误的关键点。
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'IStudentMgr' defined in class path resource [applicationContext.xml]: Initialization of bean failed; nested exception is java.lang.IllegalArgumentException: error at ::0 can't find referenced pointcut update at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:527) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456) at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:293) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:290) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:192) at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:585) at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:895) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:425) at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139) at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
[2] 解决办法
这个错误的意思是说切入点定义的语法发生错误,错误的定义如下:
@AfterReturning("com.trs.components.mgr.StudentMgr.update()")
正确的定义代码如下:
@AfterReturning("execution(* com.trs.components.mgr.StudentMgr.update(..))")
2. 切入点参数定义错误
[1] 错误详细信息如下,红色标注是错误的关键点
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'IStudentMgr' defined in class path resource [applicationContext.xml]: Initialization of bean failed; nested exception is java.lang.IllegalArgumentException: error at ::0 formal unbound in pointcut at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:527) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456) at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:293) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:290) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:192) at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:585) at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:895) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:425) at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139) at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
[2] 解决办法
产生该错误的原因是我们在使用AfterReturning注解的时候,没有定义返回的参数,但是拦截的方法中缺需要传入一个参数,比如下面的“_result”参数。如果AfterReturing注解拦截的方法需要接收参数,需要在AfterReturning中声明。
错误的代码:
@AfterReturning("execution (* com.trs.components.mgr.StudentMgr.update(..))")
public void writeAge(Object _result) {
System.out.println("result::" + _result);
System.out.println("我是另外一个切面,年龄::" + 23);
}
正确的代码(注意下面的红色字体,申明了一个返回名为“_result”的变量):
@AfterReturning(pointcut = "execution (* com.trs.components.mgr.StudentMgr.update*(..))", returning = "_result")
public void writeAge(Object _result) {
System.out.println("result::" + _result);
System.out.println("我是另外一个切面,年龄::" + 23);
}
转载于:http://blog.csdn.net/wgw335363240/article/details/7191904
- Spring的AOP常见错误(顶)
- Spring的AOP常见错误
- Spring的AOP常见错误
- Spring的AOP常见错误
- Spring AOP 5种切面方式的应用(顶)
- Spring AOP常见错误解析
- Spring的AOP配置以及常见错误(内附代码)
- 基于注解的Spring AOP的配置和使用 (顶)
- Spring中的AOP 在Advice方法中获取目标方法的参数(顶)
- Spring的AOP(一):什么是AOP
- AOP、Spring的AOP
- Spring AOP--返回通知,异常通知和环绕通知(顶)
- spring的AOP(四)----Spring AOP 编程(Advisor)
- spring的AOP(五)----Spring AOP 编程(AspectJ )
- 探析Spring AOP(二):Spring AOP的实现机制
- Spring AOP(二)(Spring中基于AOP的@AspectJ)
- Spring AOP:静态代理、动态代理和几种常见的aop配置
- spring aop错误 缺少jar
- AngularJS(03)---Http对象
- oracle的一些常规操作sql语句集
- linux文件缓存相关
- Java中IO流小结
- HDu2212
- Spring的AOP常见错误(顶)
- 控制台主程序通过调用DLL显示对话框
- 我对LDA的一点理解
- sql server data type
- $.each的用法
- 图像锐化/谱聚类中的拉普拉斯
- Android
- 通过dbms_lob.substr()转换clob字段为varchar2类型
- MPAndroidChart 教程:数据格式器 ValueFormatter(五)