Tag Archives: Mybatis-plus version Issue

serviceimpl inherits generic public impl startup error: ClassCastException (Mybatis-plus version Issue)

Project scenario:

Mybatis plus version: 3.4.3
create abstract general services for service classes and service implementation classes
eg:

service port: service extends AbstracService<T>
service: serviceimpl extends  AbstracServiceImpl<M,T> implements service 
Abstract Common Service Interface: AbstracService<T extends xxBaseEntity> extends IService<T>
Abstract Common Service Interface Implementation: AbstracServiceImpl<M extends BaseMapper<T>,T extends xxBaseEntity> extends ServiceImpl<M, T> implements AbstracService<T>

Problem Description.
Startup error message:
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


Solution:
Update mybatis-plus version to version 3.4.3.2 or later.
Introduce dependency com.baomidou.mybatisplus.extension section must be version 3.4.3.2 onwards