主要解决springboot项目引入通用mapper(tk.mybatis.mapper)的时候一些可能会踩的坑:诸如tk.mybatis.mapper.provider.base.BaseSelectProvider.<init>()
java.lang.ClassCastException: sun.reflect.generics.reflectiveObjects.TypeVariableImpl cannot be cast to java.lang.Class
import tk.mybatis.mapper.common.Mapper;
import tk.mybatis.mapper.common.MySqlMapper;
public interface BaseDao<T> extends Mapper<T>, MySqlMapper<T>{
}
<dependency>
<groupId>tk.mybatis</groupId>
<artifactId>mapper-spring-boot-starter</artifactId>
<version>2.0.0</version>
</dependency>
mapper:
mappers: cn.hy.hyerp.erp.common.dal.BaseDao
not-empty: false
identity: mysql
启动而不是import org.mybatis.spring.annotation.MapperScan;不然会报错:
Cause: java.lang.InstantiationException: tk.mybatis.mapper.provider.base.BaseSelectProvider] with root cause
java.lang.NoSuchMethodException: tk.mybatis.mapper.provider.base.BaseSelectProvider.<init>()
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'baseDao' defined in file [BaseDao.class]: Invocation of init method failed;
nested exception is tk.mybatis.mapper.MapperException: tk.mybatis.mapper.MapperException: java.lang.ClassCastException: sun.reflect.generics.reflectiveObjects.TypeVariableImpl cannot be cast to java.lang.Class
@Column(name = "personType")
private Boolean personType;