public class MyDaoImpl extends HibernateDaoSupport implements MyDao {
...
}
<bean id="MyDao" class="com.myStuff.dao.impl.MyDaoImpl"
parent="daoTmpl" /><bean id="daoTmpl" abstract="true" lazy-init="default" autowire="default"
dependency-check="default">
<property name="sessionFactory">
<ref bean="sessionFactory" />
property>
bean>
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;
@Repository(value = "MyDao")
@Transactional
public class MyDaoImpl extends HibernateDaoSupport implements MyDao {
...
}
But then I got an error saying that the SessionFactory was not initialized in the dao -
Caused by: java.lang.IllegalArgumentException: 'sessionFactory' or 'hibernateTemplate' is required
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;
@Repository(value = "MyDao")
@Transactional
public class MyDaoImpl extends HibernateDaoSupport implements MyDao {
@Autowired
public MyDaoImpl (SessionFactory sessionFactory)
super.setSessionFactory(sessionFactory);
}
...
}
and of course, you can and should remove MyDao definition from the xml file (not the daoImpl)
Hope this helps anyone who got this problem as well
- Li
No comments:
Post a Comment