这是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()方法的啊!这是怎么个情况。