spring入门(16)--spring常见错误总结 (三)

2014-11-24 10:58:06 · 作者: · 浏览: 1
an property 'deptBean': : No qualifying bean of type [www.csdn.spring.autowire.DeptBean] is defined: expected single matching bean but found 2: deptBean,deptBean1; nested exception is org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type [www.csdn.spring.autowire.DeptBean] is defined: expected single matching bean but found 2: deptBean,deptBean1

Caused by: org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type [www.csdn.spring.autowire.DeptBean] is defined: expected single matching bean but found 2: deptBean,deptBean1

这两种错误原因:都是spring配置文件中自动装配按byType时出的问题,配置文件, 红色部分为错误的解释和导致错误的原因如下:




9. 错误九

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'empBean' defined in class path resource [spring-byConstructor.xml]: Unsatisfied dependency expressed through constructor argument with index 0 of type [www.csdn.spring.autowire.DeptBean]: : No qualifying bean of type [www.csdn.spring.autowire.DeptBean] is defined: expected single matching bean but found 2: deptBean1,deptBean2; nested exception is org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type [www.csdn.spring.autowire.DeptBean] is defined: expected single matching bean but found 2: deptBean1,deptBean2

at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray

Caused by: org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type [www.csdn.spring.autowire.DeptBean] is defined: expected single matching bean but found 2: deptBean1,deptBean2

错误原因: spring配置文件中自动装配按constructor时出的问题,配置文件, 红色部分为错误的解释和导致错误的原因如下:





10. 错误十

org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Unexpected failure

during bean definition parsing

Offending resource: class path resource [spring-collection.xml]

Bean 'collectionBean'; nested exception is org.springframework.beans.factory.parsing.BeanDefinitionParsingException:

Configuration problem: element for property 'users' must specify a ref or value

Offending resource: class path resource [spring-collection.xml]

Bean 'collectionBean'

-> Property 'users'

Caused by: org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem:

element for property 'users' must specify a ref or value

Offending resource: class path resource [spring-collection.xml]

Bean 'collectionBean'

-> Property 'users'

乍一看,有些许没有头脑,但是放下心仔细看看,提示说什么users属性怎么怎么滴;还有一点提示就是说是spring-collection.xml配置文件中的错误,这就好找,找到改配置中有关users的地方,

。。。。。

这样的代码肯定不会出错了,如果是这里的错报的就不是这个错了,可能就是第一条或第二条错了;再找下一块有users的地方,找到了这里:



仔细一看真是这里的错,红色部分最开始忘了写,注释掉了上面的list注入值的方式,后面的uti标签注入值有没有写,这是在测试类中取值遍历的时候就会遍历一个空的users,这是因为是没有注入值的错,所以没有报空指针的错,报的是这种莫名其妙的错。

11. 错误十一

org.springframework.beans.factory.BeanNotOfRequiredTypeException: Bean named 'proxyFactoryBean' must be of type [www.c