一、问题Can not set final java.lang.Class field
多数据源使用时,不能正确创建数据源连接。
java.lang.IllegalArgumentException: Can not set final java.lang.Class field org.apache.ibatis.binding.MapperProxy.mapperInterface to com.baomidou.mybatisplus.core.override.MybatisMapperProxy
java.lang.IllegalArgumentException: Can not set final java.lang.Class field org.apache.ibatis.binding.MapperProxy.mapperInterface to com.baomidou.mybatisplus.core.override.MybatisMapperProxy
at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:167)
at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:171)
at sun.reflect.UnsafeFieldAccessorImpl.ensureObj(UnsafeFieldAccessorImpl.java:58)
at sun.reflect.UnsafeQualifiedObjectFieldAccessorImpl.get(UnsafeQualifiedObjectFieldAccessorImpl.java:38)
at java.lang.reflect.Field.get(Field.java:393)
at com.baomidou.dynamic.datasource.DynamicDataSourceClassResolver.targetClass(DynamicDataSourceClassResolver.java:62)
at com.baomidou.dynamic.datasource.aop.DynamicDataSourceAnnotationInterceptor.determineDatasource(DynamicDataSourceAnnotationInterceptor.java:59)
at com.baomidou.dynamic.datasource.aop.DynamicDataSourceAnnotationInterceptor.invoke(DynamicDataSourceAnnotationInterceptor.java:50)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:212)
at com.sun.proxy.$Proxy93.getOne(Unknown Source)
at com.common.templatemybatisplus.TemplateMybatisplusApplicationTests.test04(Templ
二、问题解决
版本太低,升级版本既可。
https://github.com/baomidou/dynamic-datasource-spring-boot-starter/issues/106
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>dynamic-datasource-spring-boot-starter</artifactId>
<version>2.5.6</version>
</dependency>