Reputation: 4888
In my application multiple data source have been configured, so need to create jdbcTemplate in a different name. I am getting exception when changing the jdbcTemplate name
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>
In My DAO
private JdbcTemplate jdbcTemplate1;
public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
this.jdbcTemplate1 = jdbcTemplate;
}
getting the below exception when trying to change the name
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)
I want to change the name from jdbcTemplate to any other name.How can I achieve that?
Upvotes: 0
Views: 281
Reputation: 41
it looks like you havnt changed jdbcTemplate property name to jdbcTemplate 1 , at all the places. Please recheck or share changed xml and java file.
Upvotes: 1