在我应用程序中已经配置了多个数据源,因此需要以不同的名称创建jdbcTemplate。更改jdbcTemplate名称时出现异常
ApplicationContext.xml
<bean id="reportsViewTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
<property name="dataSource" ref="ds"></property>
</bean>
<bean id="edao" class="com.myapp.dao.EmployeeDao">
<property name="jdbcTemplate1" ref="reportsViewTemplate"></property>
</bean>在我的刀中
private JdbcTemplate jdbcTemplate1;
public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
this.jdbcTemplate1 = jdbcTemplate;
}尝试更改名称时出现以下异常
Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'edao' defined in class path resource [ApplicationContext.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'jdbcTemplate1' of bean class [com.myapp.dao.EmployeeDao]: Bean property 'jdbcTemplate1' is not writable or has an invalid setter method. Did you mean 'jdbcTemplate'?
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1568)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1276)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:553)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:761)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:866)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:542)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
at com.myapp.main.MainClass.main(MainClass.java:16)我想要将名称从jdbcTemplate更改为任何其他name.How。我能做到吗?
发布于 2017-05-01 11:54:20
看起来您还没有在所有地方将jdbcTemplate属性名称更改为jdbcTemplate 1。请重新检查或共享更改的xml和java文件。
https://stackoverflow.com/questions/43713825
复制相似问题