Spring error (Org. springframework. Beans. notwritablepropertyexception) org. springframework. Beans. notwritablepropertyexception: Invalid property 'postda' of Bean class?
An exception occurs because of a property name error in the application-xxx.xml.
<Property name = "..."> the name is related to the bean's set method, and must be case sensitive.
For example:
Public class postmanageimpl extends basemanage implements postmanage {
Private postdao Dao = NULL;
Public void setpostdao (postdao ){
This. Dao = postdao;
}
}
The XML definition should be:
<Bean id = "postmanage" parent = "txproxytemplate"> <property name = "target"> <Bean class = "com. YZ. spring. service. implement. postmanageimpl "> <property name =" postdao "> <ref bean =" postdao "/> </property> for <property name =" Dao "> <ref bean =" postdao" /> </property> error </bean> </property> </bean>
Package com. bjsxt. Spring. Dao;
Public interface userdao {
Public void save (string username, string password );
}
Package com. bjsxt. Spring. Dao;
Public class userdao4mysqlimpl implements userdao {
Public void save (string username, string password ){
System. Out. println ("-------- userdao4mysqlimpl. Save ()-------");
}
}
Package com. bjsxt. Spring. Manager;
Public interface usermanager {
Public void save (string username, string password );
}
// Note that the Set Method is defined in the class file of bean, rather than in the corresponding DAO implementation.
Package com. bjsxt. Spring. Manager;
Import com. bjsxt. Spring. Dao. userdao;
Public class usermanagerimpl implements usermanager {
Private userdao;
// Public usermanagerimpl (userdao ){
// This. userdao = userdao;
//}
Public void save (string username, string password ){
This. userdao. Save (username, password );
}
Public void setuserdao (userdao ){
This. userdao = userdao;
}
}
<? XML version = "1.0" encoding = "UTF-8"?>
<Beans xmlns = "http://www.springframework.org/schema/beans"
Xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance"
Xmlns: AOP = "http://www.springframework.org/schema/aop"
Xmlns: Tx = "http://www.springframework.org/schema/tx"
Xsi: schemalocation = "http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-2.0.xsd
Http://www.springframework.org/schema/aophttp://www.springframework.org/schema/aop/spring-aop-2.0.xsd
Http://www.springframework.org/schema/txhttp://www.springframework.org/schema/tx/spring-tx-2.0.xsd>
<! -- The values of IDs in bean labels can be customized, but they cannot be renamed. The value of the Class Attribute must be the corresponding implementation class, not the interface. -->
<! -- Configure Dao, MySQL implementation and Oracle implementation -->
<Bean id = "userdao4mysqlimpl" class = "com. bjsxt. Spring. Dao. userdao4mysqlimpl"/>
<Bean id = "userdao4oracleimpl" class = "com. bjsxt. Spring. Dao. userdao4oracleimpl"/>
<! -- Configure Manager -->
<Bean id = "usermanager" class = "com. bjsxt. Spring. Manager. usermanagerimpl">
<! -- Constructor injection. The ref attribute value is the ID attribute value of the corresponding bean tag. -->
<! -- <Constructor-Arg ref = "userdao4oracleimpl"/> -->
<! -- Setter method injection. The value of the name attribute is the userdao object defined in the usermanage. Java file, and ref is the value of the ID attribute in the corresponding bean tag. -->
<Property name = "userdao" ref = "userdao4mysqlimpl"/>
<! -- <Property name = "userdao" ref = "userdao4oracleimpl"/> -->
</Bean>
</Beans>