-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
sun.reflect.generics.reflectiveObjects.TypeVariableImpl cannot be cast to java.lang.Class #38
Comments
应该是你写错了。有可能属于下面的某种情况: AMapper<A> extends Mapper<A> 或者 AMapper extends Mapper 正确的应该是 AMapper extends Mapper<A> |
刚才把代码搜了一遍,写法和上面说的一致。 我这边的场景是这样的: 这种写法就不报错 这样写就报上面的错(之所以这么折腾老代码,是觉得下面的写法优雅): |
还有一种可能就是你扫描到基类接口了。这类接口没有指定泛型,不能被扫描。 |
你用 mybatis-starter 了吗?也有可能是自动配置扫描到了接口。 |
这个有。代码写的比较乱,把能用或不能用的dependencies都放到Pom文件中了。 |
这里有一个问题,如果自定义的Mapper接口在AMapper所在包的下面或者子包下面也会报这样的错误。 |
遇到了奇怪的报错:
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:1637)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1574)
... 52 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)
... 57 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.BaseUpdateProvider.updateByPrimaryKeySelective(BaseUpdateProvider.java:64)
at sun.reflect.GeneratedMethodAccessor61.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at tk.mybatis.mapper.mapperhelper.MapperTemplate.setSqlSource(MapperTemplate.java:234)
... 58 more
The text was updated successfully, but these errors were encountered: