Bean property 'jdbc' is not writable or has an invalid setter method.

J2EE 码拜 10年前 (2015-04-14) 2917次浏览 0个评论

这是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. Does the parameter type of the setter match the return type of the getter?
Caused by: 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. Does the parameter type of the setter match the return type of the getter?
Caused by: 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. Does the parameter type of the setter match the return type of the getter?
at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:793)
at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:645)
at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:78)
at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:59)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1122)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:857)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:423)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:249)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:155)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:246)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:160)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:267)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:110)
at org.springframework.beans.factory.support.ConstructorResolver.resolveConstructorArguments(ConstructorResolver.java:389)
at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:120)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:795)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:713)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:386)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:249)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:155)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:246)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:160)
at com.spring.HelloWorldClient.main(HelloWorldClient.java:24)
我的做法:
添加了setter和getter方法,然后能够正常使用了。
但是我看到其他人的jdbctemplate注入没有加setter()和getter()方法的啊!这是怎么个情况。

Bean property 'jdbc' is not writable or has an invalid setter method.
10分
annotation

@Autowired
Bean property 'jdbc' is not writable or has an invalid setter method.
我去试试!我这貌似没有@Autowired 是版本问题么?我用的是2.0.7版本的。
Bean property 'jdbc' is not writable or has an invalid setter method.
	private JdbcTemplate jdbc;
//使用@Autowired注解之后,将<bean //class="org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor"/>
//然后我将setter函数删掉了,
//但是 jdbc对象 装入后是null。
//这可能是什么问题?哪里出错了? 
Bean property 'jdbc' is not writable or has an invalid setter method.
10分
<context:annotation-config />
Bean property 'jdbc' is not writable or has an invalid setter method.
10分
你这注解和配置混用。
Bean property 'jdbc' is not writable or has an invalid setter method.
10分
要么全是注解,要么全是xml。不要混着用。
Bean property 'jdbc' is not writable or has an invalid setter method.
(⊙o⊙)哦  搞定了!
Bean property 'jdbc' is not writable or has an invalid setter method.
好自私的人!
Bean property 'jdbc' is not writable or has an invalid setter method.
我也出现此类问题,请问怎么回事。

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明Bean property 'jdbc' is not writable or has an invalid setter method.
喜欢 (0)
[1034331897@qq.com]
分享 (0)

文章评论已关闭!