项目场景:
mybatis-plus版本:3.4.3
建立服务类和服务实现类的 抽象通用服务
eg:
service接口:service extends AbstracService<T>
service实现类:serviceimpl extends AbstracServiceImpl<M,T> implements service
抽象通用服务接口:AbstracService<T extends xxBaseEntity> extends IService<T>
抽象通用服务接口实现: AbstracServiceImpl<M extends BaseMapper<T>,T extends xxBaseEntity> extends ServiceImpl<M, T> implements AbstracService<T>
问题描述:
启动报错信息:
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [cn.xx.xx.xx.service.impl.ServiceImpl]: Constructor threw exception; nested exception is java.lang.ClassCastException: sun.reflect.generics.reflectiveObjects.TypeVariableImpl cannot be cast to java.lang.Class
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:224)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:87)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1326)
… 157 common frames omitted
Caused by: java.lang.ClassCastException: sun.reflect.generics.reflectiveObjects.TypeVariableImpl cannot be cast to java.lang.Class
at com.baomidou.mybatisplus.extension.service.impl.ServiceImpl.currentModelClass(ServiceImpl.java:88)
at com.baomidou.mybatisplus.extension.service.impl.ServiceImpl.(ServiceImpl.java:62)
at cn.lztl.assp.mall.service.impl.AbstractPromotionsServiceImpl.(AbstractPromotionsServiceImpl.java:38)
at cn.lztl.assp.mall.service.impl.ServiceImpl.(SeckillServiceImpl.java:51)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:211)
… 159 common frames omitted
解决方案:
更新mybatis-plus版本至3.4.3.2以后版本;引入依赖com.baomidou.mybatisplus.extension部分必须3.4.3.2以后版本
问题详情:https://gitee.com/baomidou/mybatis-plus/issues/I3SE8R?_from=gitee_search
参考:https://blog.csdn.net/fgangen/article/details/118313394