Hi have a Generic class in Spring, and I would like to get the generic T type class for an injected bean. I know the classic way in Java and read how Spring 4 implements Java Generics. Also, I tried to find a solution using ResolvableType but nothing works.
@Autowired
GenericDao<SpecificClass> specificdao;
public GenericDaoImpl <T> {
private Class<T> type;
public DaoImpl () {
this.type = ...?
}
public T findById(Serializable id) {
return (T) HibernateUtil.findById(type, id);
}
}
Are there any way to avoid this?
@Autowired
@Qualifier
GenericDao<SpecificClass> specificdao;
@Repository("specificdao")
public SpecificDaoImpl extends GenericDao<SpecificClass> {
public SpecificDaoImpl () {
// assuming the constructor is implemented in GenericDao
super(this.getClass())
}
}
Thanks.