Answer the question
In order to leave comments, you need to log in
Spring Beans Generics?
The project has this definition of DAO.
package ....dao.impl;<br/>
<br/>
@Repository<br/>
public class ChatSessionDaoImpl extends HibernateCrudDao<ChatSession<User<PersonalInfo, ContactInfo, LoginInfo, BusinessInfo>>> implements ChatSessionDao {<br/>
<br/>
}
<?xml version="1.0" encoding="UTF-8"?><br/>
<beans xmlns="http://www.springframework.org/schema/beans"<br/>
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"<br/>
xmlns:context="http://www.springframework.org/schema/context"<br/>
xsi:schemaLocation="http://www.springframework.org/schema/beans <a href="http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">www.springframework.org/schema/beans/spring-beans-3.0.xsd</a><br/>
<a href="http://www.springframework.org/schema/context">www.springframework.org/schema/context</a> <a href="http://www.springframework.org/schema/context/spring-context.xsd">www.springframework.org/schema/context/spring-context.xsd</a><br/>
<br/>
"><br/>
<br/>
<br/>
<context:annotation-config /><br/>
<context:component-scan base-package="....dao"/><br/>
<context:component-scan base-package="....service"/><br/>
<context:component-scan base-package="...o.dao.impl"/><br/>
<context:component-scan base-package="....service.impl"/><br/>
<br/>
Error creating bean with name 'chatSessionDaoImpl' defined in file [/.../dao/impl/ChatSessionDaoImpl.class]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [....dao.impl.ChatSessionDaoImpl]: Constructor threw exception; nested exception is java.lang.ClassCastException: sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl cannot be cast to java.lang.Class
Answer the question
In order to leave comments, you need to log in
Make a constructor for your HibernateCrudDao class that takes a class. And in the ChatSessionDaoImpl constructor use something like super(ChatSessionDaoImpl.class);
Or this solution still exists:
@SuppressWarnings("unchecked")
private Class getType() {
return (Class) ((ParameterizedType) getClass()
.getGenericSuperclass()).getActualTypeArguments()[0];
}
Can be used in a generic class to get a generic parameter.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question