日期:2014-05-18  浏览次数:20787 次

Bean property 'jdbc' is not writable or has an invalid setter method.
这是xml文件:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">

<beans>
<bean name="fileHelloWorld" class="com.spring.HelloWorld">

<constructor-arg>
<ref bean="fileHello" />
</constructor-arg>
</bean>

<bean name="fileHello" class="com.spring.HelloWorldStr">
  <property name="jdbc">
<ref bean="jdbc" />
</property>
<constructor-arg>
<value>helloworld.properties</value>
</constructor-arg>
</bean>
<bean id="dataSource1"
class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName">
<value>oracle.jdbc.driver.OracleDriver</value>
</property>
<property name="url"
value="jdbc:oracle:thin:@(description=(address=(host=localhost)(protocol=tcp)(port=1521))(connect_data=(sid=ORCL)))">
</property>
<property name="username" value="root"></property>
<property name="password" value="root"></property>
<!-- <property name="maxActive" value="100"></property> <property name="maxIdle" 
value="30"></property> <property name="maxWait" value="1000"></property> 
<property name="defaultAutoCommit" value="true"></property> <property name="removeAbandoned" 
value="true"></property> -->
</bean>
<!-- jdbc template -->
<bean id="jdbc"  class="org.springframework.jdbc.core.JdbcTemplate"
abstract="false" lazy-init="false" 
dependency-check="default">
<property name="dataSource">
<ref bean="dataSource1" />
</property>
</bean>
</beans>

这是错误信息:
八月 13, 2013 11:06:24 上午 org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from class path resource [appcontext.xml]
Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'fileHelloWorld' defined in class path resource [appcontext.xml]: Cannot resolve reference to bean 'fileHello' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'fileHello' defined in class path resource [appcontext.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'jdbc' of bean class [com.spring.HelloWorldStr]: Bean property 'jdbc' is not writable or has an invalid setter method.