mybatis 通用 mapper 使用时抛出 ClassCastException

OSC首席混子 发布于 2016/09/06 10:24
阅读 5K+
收藏 0
Caused by: java.lang.RuntimeException: java.lang.RuntimeException: java.lang.ClassCastException: sun.reflect.generics.reflectiveObjects.TypeVariableImpl cannot be cast to java.lang.Class
	at tk.mybatis.mapper.mapperhelper.MapperHelper.setSqlSource(MapperHelper.java:247)
	at tk.mybatis.mapper.mapperhelper.MapperHelper.processConfiguration(MapperHelper.java:310)
	at tk.mybatis.spring.mapper.MapperFactoryBean.checkDaoConfig(MapperFactoryBean.java:54)
	at org.springframework.dao.support.DaoSupport.afterPropertiesSet(DaoSupport.java:44)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1631)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1568)
	... 44 more
Caused by: java.lang.RuntimeException: java.lang.ClassCastException: sun.reflect.generics.reflectiveObjects.TypeVariableImpl cannot be cast to java.lang.Class
	at tk.mybatis.mapper.mapperhelper.MapperTemplate.setSqlSource(MapperTemplate.java:246)
	at tk.mybatis.mapper.mapperhelper.MapperHelper.setSqlSource(MapperHelper.java:244)
	... 49 more
Caused by: java.lang.ClassCastException: sun.reflect.generics.reflectiveObjects.TypeVariableImpl cannot be cast to java.lang.Class
	at tk.mybatis.mapper.mapperhelper.MapperTemplate.getEntityClass(MapperTemplate.java:278)
	at tk.mybatis.mapper.provider.base.BaseSelectProvider.select(BaseSelectProvider.java:67)
	at tk.mybatis.mapper.provider.base.BaseSelectProvider.selectByRowBounds(BaseSelectProvider.java:85)
	at sun.reflect.GeneratedMethodAccessor19.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:597)
	at tk.mybatis.mapper.mapperhelper.MapperTemplate.setSqlSource(MapperTemplate.java:234)
	... 50 more



加载中
0
太黑_thj
太黑_thj
类型转换失败,看下你的model得变量类型跟数据库数据是否对了上了,还有xml里面的类型是否声明了
OSC首席混子
OSC首席混子
@太黑的忧郁情怀 这个异常是在初始化阶段报的,还没有完成注入呢
0
Liuzh_533
Liuzh_533
必须指定泛型类型。
OSC首席混子
OSC首席混子
@Liuzh_533 我参照了这个项目 https://github.com/abel533/Mybatis-Spring 并且也指定了泛型的类型了3
0
OSC首席混子
OSC首席混子

引用来自“Liuzh_533”的评论

必须指定泛型类型。
回复 @Liuzh_533 : public interface IBaseService<T> ;
public interface ISysStaffService extends IBaseService<SysStaff>;
@Service
public abstract class AbstractBaseService<T> implements IBaseService<T> ;
@Service
public class SysStaffServiceImpl extends AbstractBaseService<SysStaff> implements ISysStaffService{


};
这样对么? 
Liuzh_533
Liuzh_533
可能是这儿的问题:ISysStaffService extends IBaseService<SysStaff>;
0
J
Jason
你把MyMapper放到了mapperScannerConfigurer.setBasePackage的包里面了,MyMapper不能和其他Mapper一样被扫描到。
0
M
Moonssang

评论只为点赞

返回顶部
顶部