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的更多相关文章

  1. [Exception Spring 1] - Attribute value must not be null

    java.lang.IllegalArgumentException: Attribute value must not be null at org.springframework.util.Ass ...

  2. 基于注解的Spring AOP的配置和使用

    摘要: 基于注解的Spring AOP的配置和使用 AOP是OOP的延续,是Aspect Oriented Programming的缩写,意思是面向切面编程.可以通过预编译方式和运行期动态代理实现在不 ...

  3. Java Hour 66 Spring 相关

    这章简单的来了解下Spring 和 Hibernate 是如何勾搭在一起的. <bean id="sessionFactory" class="org.spring ...

  4. 基于注解的Spring AOP的配置和使用--转载

    AOP是OOP的延续,是Aspect Oriented Programming的缩写,意思是面向切面编程.可以通过预编译方式和运行期动态代理实现在不修改源代码的情况下给程序动态统一添加功能的一种技术. ...

  5. Spring day01笔记

    struts:web层,比较简单(ValueStack值栈,拦截器) hibernate:dao层,知识点杂 spring:service层,重要,讲多少用多少 --> [了解]   sprin ...

  6. Spring AOP 注解和xml实现 --转载

    AOP是OOP的延续,是Aspect Oriented Programming的缩写,意思是面向切面编程.可以通过预编译方式和运行期动态代理实现在不修改源代码的情况下给程序动态统一添加功能的一种技术. ...

  7. 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 ...

  8. Spring(二)--FactoryBean、bean的后置处理器、数据库连接池、引用外部文件、使用注解配置bean等

    实验1:配置通过静态工厂方法创建的bean  [通过静态方法提供实例对象,工厂类本身不需要实例化!] 1.创建静态工厂类 public class StaticFactory { private st ...

  9. 利用 FormData 对象和 Spring MVC 配合可以实现Ajax文件上载功能

    Ajax文件上载 利用 FormData 对象和 Spring MVC 配合可以实现Ajax文件上载功能: 步骤 导入组件并准备静态脚本 <dependency> <groupId& ...

  10. 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 ...

随机推荐

  1. JavaScript 新手的踩坑日记

    引语 在1995年5月,Eich 大神在10天内就写出了第一个脚本语言的版本,JavaScript 的第一个代号是 Mocha,Marc Andreesen 起的这个名字.由于商标问题以及很多产品已经 ...

  2. 用资源管理器右键编译 Visual Studio 解决方案文件

    每次改动 VC 工程之后都要重新编译,每次 VS 又会生成调试数据库文件,很费时间,于是研究了一下如何在资源管理器中直接编译,还真发现了解决办法. 以下是适用 Visual Studio 2008 的 ...

  3. memcached-session-manager配置

    原文地址: http://chenzhou123520.iteye.com/blog/1650212 声明:本篇文章是根据memcached-session-manager官方配置方法wiki页面翻译 ...

  4. 求好用的在线手册编写工具,能编写像bootstrap在线Doc那种的,想为OpenCenter写个在线手册

    原文地址:http://www.oschina.net/question/1014458_225711 各位OSCer的开源项目的在线说明文档都是用什么写的呢? 类似 http://v3.bootcs ...

  5. java中ant包中的org.apache.tools.zip实现压缩和解压缩

    其实apache中的ant包(请自行GOOGLE之ant.jar)中有一个更好的类,已经支持中文了,我们就不重复制造轮子了,拿来用吧,这里最主要的功能是实现了 可以指定多个文件 到同一个压缩包的功能 ...

  6. Iptables静态防火墙基础教程

    文章目录检查Iptables是否安装Iptables相关的文件配置Iptables规则自定义规则保存规则 Iptables对于刚入门Linux的新手都比较难理解和配置.但是如果你掌握了其中的诀窍,你就 ...

  7. 为Eclipse添加C/C++开发工具

    如果你是一个C / C ++开发人员,正在为你的工作寻找一款开源的IDE工具,你可以考虑基于Eclipse的IDE. Eclipse中拥有一个可扩展的插件系统定制让你轻松的来定制你的IDE,它可以支持 ...

  8. EasyUI 常规用法

    (function () {     // 获取树的路径,如 组织分类 > YHBH > 湖南省卫生厅 > 湖南省长沙市     var getBreadcrumbs = funct ...

  9. C++11学习

    转自: https://www.cnblogs.com/llguanli/p/8732481.html Boost教程: http://zh.highscore.de/cpp/boost/ 本章目的: ...

  10. nth-digit

    https://leetcode.com/problems/nth-digit/ public class Solution { public int findNthDigit(int n) { in ...