I would like to use @Repository spring annotation to avoid adding bean in context.xml. I use ibatis integration, so my repository class looks like this
@Repository("userDao")
public class UserDaoMybatis extends SqlMapClientDaoSupport implements UserDao {
// ...
}
SqlMapClientDaoSupport (spring library class) has final method for setting required property which is not annotated with @Autowired or @Resourse
public final void setSqlMapClient(SqlMapClient sqlMapClient) {
if (!this.externalTemplate) {
this.sqlMapClientTemplate.setSqlMapClient(sqlMapClient);
}
}
SqlMapClient bean is defined in spring context.xml. If userDao bean is defined in XML it works fine, but when I put @Repository annotation and remove bean declaration I get the following exception
java.lang.IllegalArgumentException: Property 'sqlMapClient' is required
A workaround can be to add new method like
@Aitowired
injectSqlMapClient(SqlMapClient sqlMapClient) {
setSqlMapClient(sqlMapClient);
}
but it looks ugly
Is there any other way yo inject the property without having defined?