In the learning spring process encountered a variety of unusual errors, here to do a summary, hoping to meet similar mistakes students to share.
1. Error One
Error creating Bean with Name ' Helloserviceimpl ' defined in class path resource [Spring-service.xml]: Error setting proper Ty values; Nested exception is Org.springframework.beans.NotWritablePropertyException:Invalid property ' Hellodao ' of Bean class [ Www.csdn.spring.service.impl.HelloServiceImpl]: Bean property ' Hellodao ' are not writable or has a invalid setter method. Does the parameter type of the setter match the return type of the getter?
caused By:org.springframework.beans.NotWritablePropertyException:Invalid property ' Hellodao ' of Bean class
This type of error is: You typically create a DAO spring file, such as Spring-dao, which has a spring file that creates a service, Referring to the ID name defined in the DAO in Spring-service.xml, the error is caused by the failure to write the service implementation class forgetting to write a corresponding DAO setter method, known as dependency injection
Like what:
Private Hellodao Hellodao;
Set dependency Injection is important, do not write an error, can not read and write Hellodao this property
Publicvoid Sethellodao (Hellodao Hellodao) {
System.out
. println ("Inversion of Control: the application itself is not responsible for creating Hellodao objects, but the spring container is responsible for creating, managing, maintaining, so that control transfers, called reversals." "
+ "can inject the Hellodao object by means of a dependency injection");
This.hellodao = Hellodao;
}
2. Error two
Configuration problem:failed to import beans definitions from relative location [spring-dao.xml]offending resource:class Path resource [spring.xml]; Nested exception is Org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException:Line 9 in XML document from Class path resource [Spring-dao.xml] is invalid; Nested exception is Org.xml.sax.SAXParseException:Open quote are expected for attribute ' {1} ' associated with an element t Ype "Scope".
caused By:org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException:Line 9 in XML document from class path Resource [spring-dao.xml] is invalid; Nested exception is Org.xml.sax.SAXParseException:Open quote are expected for
Caused By:org.xml.sax.SAXParseException:Open quote is expected for attribute ' {1} ' associated with an element type ' SCO PE ".
This kind of mistake is sloppy error, in the corresponding spring's configuration file, the bean label's scope attribute is omitted to be quoted, and in the configuration file China will not complain, but it will be wrong when it is run, and the cause of the error is usually the omission of the quotation mark in the copy, and the original quotation mark is covered. Causes the last property to have no quotes.
<bean id= "Hellodaoimpl" class= "Www.csdn.spring.dao.impl.HelloDaoImpl"
Scope= "Prototype" ></bean>
To write wrongly:
Bean id= "Hellodaoimpl" class= "Www.csdn.spring.dao.impl.HelloDaoImpl"
Scope=prototype></bean>
3. Error three
No Bean named ' helloserviceimp ' is defined
At Org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition
This error but no caused by statement errors are generally used when the word is wrong, where the wrong place is in the Java class, the class in the reference ID when the wrong words; for example, here's the mistake, note the following red text:
HelloService HelloService2 = (helloservice) context.getbean ("Helloserviceimp", Helloserviceimpl.class);
<bean id= "Helloserviceimpl" class= "Www.csdn.spring.service.impl.HelloServiceImpl" scope= "Singleton" False ">
<property name= "Hellodao" ref= "Hellodaoimpl"/>
</bean>
The eagle-eyed guys are probably looking at it. These two words are not the same, the ID of the method in which the bean was fetched wrote an "I" less, causing the spring container to be unrecognized when it was read. Be careful later.