Another option is to annotate the interface implementing bean with name on one side and to annotate with qualifier pointing to created name on the other side :) Here is a quick example I am using in my project :
public interface IDAO {
public void insert(T model);
public void update(T model);
public void delete(T model);
}
Abstract class as predecessor :
public abstract class AbstractHibernateDAO {
protected SessionFactory sessionFactory;
protected Session currentSession() {
return sessionFactory.getCurrentSession();
}
}
Implementation of abstract class for entity user:
@Repository(value = "userRepository")
public class UserDAO extends AbstractHibernateDAO implements IDAO {
@Autowired
public UserDAO(SessionFactory sessionFactory) {
this.sessionFactory = sessionFactory;
}
@Override
public void insert(User user) {
currentSession().save(user);
}
@Override
public void update(User user) {
currentSession().update(user);
}
@Override
public void delete(User user) {
currentSession().delete(user);
}
}
And finally injecting right implementation:
@Resource
@Qualifier(value = "userRepository")
IDAO userPersistence;