I am integrating Struts 2-Spring 3-Hibernate 4 application.
Please suggest some solution.
I am getting following error:
StacktraceCode:
org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'masterDao' defined in ServletContext resource [/WEB-INF/spring-config.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyExcep tion: Invalid property 'sessionFactory' of bean class [in.nic.eservicebook.dao.MasterDaoImpl]: Bean property 'sessionFactory' 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.factory.support.Abstract AutowireCapableBeanFactory.applyPropertyValues(Abs tractAutowireCapableBeanFactory.java:1396)
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.populateBean(AbstractAu towireCapableBeanFactory.java:1118)
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.doCreateBean(AbstractAu towireCapableBeanFactory.java:517)
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean(AbstractAuto wireCapableBeanFactory.java:456)
at org.springframework.beans.factory.support.Abstract BeanFactory$1.getObject(AbstractBeanFactory.java:2 94)
at org.springframework.beans.factory.support.DefaultS ingletonBeanRegistry.getSingleton(DefaultSingleton BeanRegistry.java:225)
at org.springframework.beans.factory.support.Abstract BeanFactory.doGetBean(AbstractBeanFactory.java:291 )
at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:193)
at org.springframework.beans.factory.support.DefaultL istableBeanFactory.preInstantiateSingletons(Defaul tListableBeanFactory.java:585)
at org.springframework.context.support.AbstractApplic ationContext.finishBeanFactoryInitialization(Abstr actApplicationContext.java:913)
at org.springframework.context.support.AbstractApplic ationContext.refresh(AbstractApplicationContext.ja va:464)
at org.springframework.web.context.ContextLoader.conf igureAndRefreshWebApplicationContext(ContextLoader .java:384)
at org.springframework.web.context.ContextLoader.init WebApplicationContext(ContextLoader.java:283)
at org.springframework.web.context.ContextLoaderListe ner.contextInitialized(ContextLoaderListener.java: 111)
at org.apache.catalina.core.StandardContext.listenerS tart(StandardContext.java:4723)
at org.apache.catalina.core.StandardContext$1.call(St andardContext.java:5226)
at org.apache.catalina.core.StandardContext$1.call(St andardContext.java:5221)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker( Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run (Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: org.springframework.beans.NotWritablePropertyExcep tion: Invalid property 'sessionFactory' of bean class [in.nic.eservicebook.dao.MasterDaoImpl]: Bean property 'sessionFactory' 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.setPrope rtyValue(BeanWrapperImpl.java:1064)
at org.springframework.beans.BeanWrapperImpl.setPrope rtyValue(BeanWrapperImpl.java:924)
at org.springframework.beans.AbstractPropertyAccessor .setPropertyValues(AbstractPropertyAccessor.java:7 6)
at org.springframework.beans.AbstractPropertyAccessor .setPropertyValues(AbstractPropertyAccessor.java:5 8)
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.applyPropertyValues(Abs tractAutowireCapableBeanFactory.java:1393)
... 20 more
spring-config.xmlCode:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schem...-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schem...ontext-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
<context:component-scan base-package="in.nic.eservicebook" />
<tx:annotation-driven transaction-manager="transactionManager"/>
<bean id="propertyConfigurer"
class="org.springframework.beans.factory.config.Pr opertyPlaceholderConfigurer">
<property name="location">
<value>/WEB-INF/databaseConfig.properties</value>
</property>
</bean>
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverM anagerDataSource">
<property name="driverClassName" value="${db.driverClassName}" />
<property name="url" value="${db.databaseurl}" />
<property name="username" value="${db.username}" />
<property name="password" value="${db.password}" />
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate4.LocalSes sionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="annotatedClasses">
<list>
<value>in.nic.eservicebook.pojo.Title</value>
<value>in.nic.eservicebook.pojo.BloodGroup</value>
<value>in.nic.eservicebook.pojo.Community</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">${hibernate.dialect}</prop>
<prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
</props>
</property>
</bean>
<bean id="masterDao" class="in.nic.eservicebook.dao.MasterDaoImpl">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<bean id="transactionManager" class="org.springframework.orm.hibernate4.Hibernat eTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
</beans>
MasterDaoImpl.javaCode:
package in.nic.eservicebook.dao;
import in.nic.eservicebook.pojo.BloodGroup;
import in.nic.eservicebook.pojo.Community;
import in.nic.eservicebook.pojo.Title;
import in.nic.util.HibernateUtil;
import java.util.List;
import org.hibernate.HibernateException;
import org.hibernate.SessionFactory;
import org.hibernate.Session;
import org.springframework.beans.factory.annotation.Autow ired;
import org.springframework.stereotype.Repository;
@Repository("masterDao")
public class MasterDaoImpl implements MasterDao {
@Autowired
private SessionFactory sessionFactory;
@SuppressWarnings("unchecked")
public List<Title> listTitle() {
return (List<Title>) sessionFactory.getCurrentSession().createQuery("fr om Title").list();
}
}