<bean id="baseDao" class="com.iwiz.dao.impl.BaseDaoImpl">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
<bean id="noteDao" class="com.iwiz.dao.impl.NoteDaoImpl" parent="baseDao"></bean>
<bean id="baseService" class="com.iwiz.service.impl.BaseServiceImpl">
<property name="baseDao" ref="baseDao"></property>
</bean>
<bean id="noteService" class="com.iwiz.service.impl.NoteServiceImpl" parent="baseService">
<property name="noteDao" ref="noteDao"></property>
</bean>
public class BaseDaoImpl<T, PK extends Serializable> implements BaseDao<T, PK> {
private Class<T> entityClass;
public BaseDaoImpl() {
this.entityClass = null;
Class<T> c = (Class<T>) getClass();
Type type = c.getGenericSuperclass();
if(type instanceof ParameterizedType) {
Type[] parameterizedType = ((ParameterizedType)type).getActualTypeArguments();
this.entityClass = (Class<T>) parameterizedType[0];
}
}
public T findById(PK id) {
return (T) getSession().load(entityClass, id);
}
}
public class NoteServiceImpl extends BaseServiceImpl<Note, String> implements NoteService {
private NoteDao noteDao;
public void setBaseDao(NoteDao noteDao) {
super.setBaseDao(noteDao);
}
public void setNoteDao(NoteDao noteDao) {
this.noteDao = noteDao;
}
}
tomcat在启动的时候并没有执行红色字体的代码,导致调用findById时entityClass为空值,但是BaseDaoImpl的构造方法已经把所需要的类都通过反射得到了呀,怎么回事呀?怎样才能让tomcat启动就能执行红色字体的代码?我漏了什么配置了还是...?