Javadoc to SqlSessionDaoSupport class says:
...@Autowired was removed from setSqlSessionTemplate and setSqlSessionFactory in version 1.2.0.
Why? In this case I have to manualy set sqlSessionFactory to my daos and also to test classes(I use dbUnit for persistance tests)
@Autowired was removed according to this issue : https://code.google.com/p/mybatis/issues/detail?id=763
As a generic purpose framework, MyBatis should not make strong assertions such as "There's only one sqlSessionFactory in the ApplicationContext", that's why @Autowired was removed.
As a workaround, you could write your own MyAppSqlSessionDaoSupport that extends SqlSessionDaoSupport, and override setSqlSessionFactory(...) with
@Autowired
public void setSqlSessionFactory(SqlSessionFactory sqlSessionFactory) {
if (!this.externalSqlSession) {
this.sqlSession = new SqlSessionTemplate(sqlSessionFactory);
}
}
Then, make your DAOs extends MyAppSqlSessionDaoSupport instead of SqlSessionDaoSupport.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With