EXCEPTION-SPRING
CreateTime--2016年8月23日09:00:47
Author:Marydon
声明:异常类文章主要是记录了我遇到的异常信息及解决方案,解决方案大部分都是百度解决的,(这里只是针对我遇到的做个汇总),特此声明!
异常一(Aop异常)
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [config/applicationContext.xml]: BeanPostProcessor before instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.aop.support.DefaultBeanFactoryPointcutAdvisor#0': Cannot resolve reference to bean 'pc' while setting bean property 'pointcut'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'pc': Instantiation of bean failed; nested exception is java.lang.NoClassDefFoundError: org/aspectj/weaver/BCException
解决方案:
添加jar包 aspectjweaver.jar
异常二
config/applicationContext.xml不存在
解决方案:
添加:classpath:即"classpath:config/applicationContext.xml"
异常五(Aop异常)
Exception in thread "main" java.lang.ClassCastException: com.sun.proxy.$Proxy0 cannot be cast to com.service.user.bo.impl.BoUser
解析:
Spring的文档中这么写的:Spring AOP部分使用JDK动态代理或者CGLIB来为目标对象创建代理。如果被代理的目标实现了至少一个接口,则会使用JDK动态代理。所有该目标类型实现的接口都将被代理。若该目标对象没有实现任何接口,则创建一个CGLIB代理。 所以,解决办法是,如果用JDK动态代理,就必须为被代理的目标实现一个接口(要注意的地方是:需要将ctx.getBean()方法的返回值用接口类型接收);如果使用CGLIB强制代理,就必选事先将CGLIB包导入项目,设置beanNameAutoProxyCreator的proxyTargetClass属性为true。
解决方案:
这里BoUser实现了接口IBoUser,所以会使用JDK动态代理,从而使(BoUser)applicationContext.getBean("userBo")强制转换的时候报错(因为实现IBoUser接口的代理类是属于BoUser子类)。因此需要使用CGLIB强制代理。需要在springContext.xml中增加如下配置:
<aop:aspectj-autoproxy proxy-target-class="true"/>
UpdateTime--2017年3月1日11:52:23
异常六(placeholder异常)
org.springframework.beans.factory.BeanDefinitionStoreException: Invalid bean definition with name 'amqConnectionFactory' defined in class path resource [com/xyhsoft/demo/conf/spring/activeMQ.xml]: Could not resolve placeholder 'brokerUrl' in string value "${brokerUrl}"
原因:
配置了多个 org.springframework.beans.factory.config.PropertyPlaceholderConfigurer
这个配置用于 xml 中的占位符,如下:
<property name="driverClassName" value="${jdbc.driverClassName}" />
<property name="url" value="${jdbc.url}" />
<property name="username" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />
解决方案:
找到xml文件中配置第一个PropertyPlaceholderConfigurer的位置(一般是配置加载数据源文件的地方),将ignoreUnresolvablePlaceholders的值设为true即可。如,
<bean id="propertyConfig" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath:db.properties</value>
</list>
</property>
<property name="ignoreUnresolvablePlaceholders" value="true" />
</bean>
<!--
这个配置告诉spring,当某个placeholder无法找到时,先不要报错,并尝试用另一个PropertyPlaceholderConfigurer来设置placeholder的值。
-->
EXCEPTION-SPRING的更多相关文章
- [Exception Spring 1] - Attribute value must not be null
java.lang.IllegalArgumentException: Attribute value must not be null at org.springframework.util.Ass ...
- 基于注解的Spring AOP的配置和使用
摘要: 基于注解的Spring AOP的配置和使用 AOP是OOP的延续,是Aspect Oriented Programming的缩写,意思是面向切面编程.可以通过预编译方式和运行期动态代理实现在不 ...
- Java Hour 66 Spring 相关
这章简单的来了解下Spring 和 Hibernate 是如何勾搭在一起的. <bean id="sessionFactory" class="org.spring ...
- 基于注解的Spring AOP的配置和使用--转载
AOP是OOP的延续,是Aspect Oriented Programming的缩写,意思是面向切面编程.可以通过预编译方式和运行期动态代理实现在不修改源代码的情况下给程序动态统一添加功能的一种技术. ...
- Spring day01笔记
struts:web层,比较简单(ValueStack值栈,拦截器) hibernate:dao层,知识点杂 spring:service层,重要,讲多少用多少 --> [了解] sprin ...
- Spring AOP 注解和xml实现 --转载
AOP是OOP的延续,是Aspect Oriented Programming的缩写,意思是面向切面编程.可以通过预编译方式和运行期动态代理实现在不修改源代码的情况下给程序动态统一添加功能的一种技术. ...
- SPRING IN ACTION 第4版笔记-第四章ASPECT-ORIENTED SPRING-002-AOP术语解析
一. 1.Advice Advice是切面的要做的操作,它定义了what.when(什么时候要做什么事) aspects have a purpose—a job they’re meant to d ...
- Spring(二)--FactoryBean、bean的后置处理器、数据库连接池、引用外部文件、使用注解配置bean等
实验1:配置通过静态工厂方法创建的bean [通过静态方法提供实例对象,工厂类本身不需要实例化!] 1.创建静态工厂类 public class StaticFactory { private st ...
- 利用 FormData 对象和 Spring MVC 配合可以实现Ajax文件上载功能
Ajax文件上载 利用 FormData 对象和 Spring MVC 配合可以实现Ajax文件上载功能: 步骤 导入组件并准备静态脚本 <dependency> <groupId& ...
- Spring Security(三十):9.5 Access-Control (Authorization) in Spring Security
The main interface responsible for making access-control decisions in Spring Security is the AccessD ...
随机推荐
- 订阅Linux内核邮件列表
http://www.wowotech.net/sort/linux_application/lkml.html https://kernelnewbies.org/ML https://lkml.o ...
- ZOJ3673:1729
1729 is the natural number following 1728 and preceding 1730. It is also known as the Hardy-Ramanuja ...
- Vue 组件 data为什么是函数?
在创建或注册模板的时候,传入一个data属性作为用来绑定的数据.但是在组件中,data必须是一个函数,而不能直接把一个对象赋值给它. Vue.component('my-component', { t ...
- CNZZ站点流量统计原理简析
这是我的域名www.iyizhan.com.暂无内容,当中仅仅有一个页面index.html. 在index.html上放置了例如以下的 js 脚本: <script src="ht ...
- MVC扩展ModelBinder,通过继承DefaultModelBinder把表单数据封装成类作为action参数
把视图省.市.街道表单数据,封装成一个类,作为action参数.如下: action方法参数类型: namespace MvcApplication1.Models{ public class ...
- Accepting PayPal in games(完整的Paypal在Unity的支付)
Hello and welcome back to my blog! In this article I’m going to talk about the process of acceptin ...
- python文本 判断对象里面是否是类字符串
python文本 判断对象里面是否是类字符串 场景: 判断对象里面是否是类字符串 一般立刻会想到使用type()来实现 >>> def isExactlyAString(obj): ...
- andriod 播放mp4
权限 <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/> activi ...
- [翻译] Fast Image Cache
https://github.com/path/FastImageCache Fast Image Cache is an efficient, persistent, and—above all—f ...
- java.lang.UnsatisfiedLinkError:no dll in java.library.path终极解决之道
Java调用Dll时,会出现no dll in java.library.path异常,在Java Project中不常见,因为只要将Dll拷贝到system32目录下即可: 但若是 ...