Service配置文件中这么写:
但是dao配置文件中却这么写:
bean id="helloDaoImpl" class="www.csdn.spring.dao.impl.HelloDaoImpl"
scope="prototype">
写到这大家就清楚了吧,与上一个错误基本上一样,都是单词写错的错误,只不过不同的是上一个错误是在java类中引用id的时候写错单词出的错,而这一个错误是在spring配置文件中国引用id出的错,万变不离其宗,错误的额原因都是单词写错,今后细心即可。
5. 错误五
Cannot find class [www.csdn.spring.dao.imp.HelloDaoImpl] for bean with name 'helloDaoImpl' defined in ServletContext resource [/WEB-INF/applicationContext.xml]; nested exception is java.lang.ClassNotFoundException:www.csdn.spring.dao.imp.HelloDaoImpl
Caused by: java.lang.ClassNotFoundException: www.csdn.spring.dao.HelloDaoImpl
错误原因:倒错包了,我的web项目HelloDaoImpl在dao.impl包下而不是dao包下。所以包这样的错,看一下spring配置文具店额classes标签的值导入的类包名是否正确
6. 错误六
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'employeeBean' defined in class path resource [spring-constructor.xml]: Unsatisfied dependency expressed through constructor argument with index 2 of type [double]: Ambiguous constructor argument types - did you specify the correct bean references as constructor arguments
错误原因:bean实例类中的属性类型与spring配置文件中的构造器属性类型不对应所导致,这种情况多出在使用类型指定构造器参数;比如:
类中属性如下,重点注意红色部分:
private String name;
private String sex;
private doublesalary;
spring配置文件中的构造器标签
这种错误是因为构造器中的type属性不会自动对应拆箱装箱属性类型,简单点说就是类中使用的是基本数据类型,配置文件中对应的type属性值就要是基本数据类型;类中使用的是类类型,配置文件中对应的type属性值就要是包名加上类类型;
还有一种原因就是不对应的原因,constructor-arg直接写错了,比如:private doublesalary;对应了
或者顺序不对的情况下回出现赋值错误,比如同时存在两个相同类型的属性,name应该为“杨凯”,如果sex在配置文件的位置与name的颠倒了,会出现name=“男”的情况
7. 错误七
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'memberBean' defined in class path resource [spring-construtor.xml]: Initialization of bean failed; nested exception is org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type 'java.lang.String' to required type 'www.csdn.spring.constructor.Member' for property 'member'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [java.lang.String] to required type [www.csdn.spring.constructor.Member] for property 'member': no matching editors or conversion strategy found
Caused by: org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type 'java.lang.String' to required type 'www.csdn.spring.constructor.Member' for property 'member'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [java.lang.String] to required type [www.csdn.spring.constructor.Member] for property 'member': no matching editors or conversion strategy found
错误原因:这种情况是一个bean实例引用另一个bean实例对象,而引用的那个bean实例对象为空,但是在改bean实例的配置文件中又错误指明空值。举个例子说明:
关键看红色部分,红色部分是正确的写法,这样写引用空值对象才不会报错,但是如果你像上面引用nam属性那样指明value=“null”就会出现改错。
8. 错误八
错误一:
org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Bean name 'deptBean' is already used in this
Offending resource: class path resource [spring-byType.xml]
错误二:
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'empBean' defined in class path resource [spring-byType.xml]: Unsatisfied dependency expressed through be