java11 升级到java17 项目启动正常,执行mybatis 查询的时候报错
根据报错信息怀疑mybatis xml 配置问题,发现其实没有问题,jdk11 的时候正常启动
reating a new SqlSession
SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@3c88e19e] was not registered for synchronization because synchronization is not active
JDBC Connection [org.apache.shardingsphere.shardingjdbc.jdbc.core.connection.ShardingConnection@5b6098ff] will not be managed by Spring
==> Preparing: select id, user_id as userId, order_id as orderId, remark, create_time as createTime from t_order where order_id=?
==> Parameters: 12(Long)
Closing non transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@3c88e19e]
2021-09-20 22:47:33.431 ERROR 19452 --- [nio-9090-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.PersistenceException:
### Error querying database. Cause: java.lang.reflect.InaccessibleObjectException: Unable to make field private static final long java.lang.Number.serialVersionUID accessible: module java.base does not "opens java.lang" to unnamed module @708f5957
### The error may exist in file [D:\java\IdeaProjects\sharding-demo\target\classes\mapper\OrderMapper.xml]
### The error may involve defaultParameterMap
### The error occurred while setting parameters
### SQL: select id, user_id as userId, order_id as orderId, remark, create_time as createTime from t_order where order_id=?
### Cause: java.lang.reflect.InaccessibleObjectException: Unable to make field private static final long java.lang.Number.serialVersionUID accessible: module java.base does not "opens java.lang" to unnamed module @708f5957] with root cause
java.lang.reflect.InaccessibleObjectException: Unable to make field private static final long java.lang.Number.serialVersionUID accessible: module java.base does not "opens java.lang" to unnamed module @708f5957
at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:354) ~[na:na]
at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:297) ~[na:na]
at java.base/java.lang.reflect.Field.checkCanSetAccessible(Field.java:178) ~[na:na]
at java.base/java.lang.reflect.AccessibleObject.setAccessible(AccessibleObject.java:130) ~[na:na]
at org.codehaus.groovy.reflection.CachedClass$1$1.run(CachedClass.java:55) ~[groovy-2.4.5-indy.jar:2.4.5]
at java.base/java.security.AccessController.doPrivileged(AccessController.java:318) ~[na:na]
at org.codehaus.groovy.reflection.CachedClass$1.initValue(CachedClass.java:50) ~[groovy-2.4.5-indy.jar:2.4.5]
at org.codehaus.groovy.reflection.CachedClass$1.initValue(CachedClass.java:48) ~[groovy-2.4.5-indy.jar:2.4.5]
at org.codehaus.groovy.util.LazyReference.getLocked(LazyReference.java:49) ~[groovy-2.4.5-indy.jar:2.4.5]
at org.codehaus.groovy.util.LazyReference.get(LazyReference.java:36) ~[groovy-2.4.5-indy.jar:2.4.5]
at org.codehaus.groovy.reflection.CachedClass.getFields(CachedClass.java:264) ~[groovy-2.4.5-indy.jar:2.4.5]
at groovy.lang.MetaClassImpl.addFields(MetaClassImpl.java:2377) ~[groovy-2.4.5-indy.jar:2.4.5]
at groovy.lang.MetaClassImpl.inheritFields(MetaClassImpl.java:2372) ~[groovy-2.4.5-indy.jar:2.4.5]
at groovy.lang.MetaClassImpl.setupProperties(MetaClassImpl.java:2259) ~[groovy-2.4.5-indy.jar:2.4.5]
at groovy.lang.MetaClassImpl.addProperties(MetaClassImpl.java:3302) ~[groovy-2.4.5-indy.jar:2.4.5]
at groovy.lang.MetaClassImpl.initialize(MetaClassImpl.java:3266) ~[groovy-2.4.5-indy.jar:2.4.5]
at org.codehaus.groovy.reflection.ClassInfo.getMetaClassUnderLock(ClassInfo.java:254) ~[groovy-2.4.5-indy.jar:2.4.5]
at org.codehaus.groovy.reflection.ClassInfo.getMetaClass(ClassInfo.java:285) ~[groovy-2.4.5-indy.jar:2.4.5]
at org.codehaus.groovy.reflection.ClassInfo.getMetaClass(ClassInfo.java:295) ~[groovy-2.4.5-indy.jar:2.4.5]
at org.codehaus.groovy.runtime.metaclass.MetaClassRegistryImpl.getMetaClass(MetaClassRegistryImpl.java:261) ~[groovy-2.4.5-indy.jar:2.4.5]
at org.codehaus.groovy.runtime.InvokerHelper.getMetaClass(InvokerHelper.java:873) ~[groovy-2.4.5-indy.jar:2.4.5]
at org.codehaus.groovy.runtime.callsite.CallSiteArray.createPojoSite(CallSiteArray.java:125) ~[groovy-2.4.5-indy.jar:2.4.5]
at org.codehaus.groovy.runtime.callsite.CallSiteArray.createCallSite(CallSiteArray.java:166) ~[groovy-2.4.5-indy.jar:2.4.5]
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48) ~[groovy-2.4.5-indy.jar:2.4.5]
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113) ~[groovy-2.4.5-indy.jar:2.4.5]
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125) ~[groovy-2.4.5-indy.jar:2.4.5]
at Script6$_run_closure1.doCall(Script6.groovy:1) ~[na:na]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) ~[na:na]
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
at java.base/java.lang.reflect.Method.invoke(Method.java:568) ~[na:na]
at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:93) ~[groovy-2.4.5-indy.jar:2.4.5]
at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325) ~[groovy-2.4.5-indy.jar:2.4.5]
at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:294) ~[groovy-2.4.5-indy.jar:2.4.5]
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1019) ~[groovy-2.4.5-indy.jar:2.4.5]
at groovy.lang.Closure.call(Closure.java:426) ~[groovy-2.4.5-indy.jar:2.4.5]
at groovy.lang.Closure.call(Closure.java:420) ~[groovy-2.4.5-indy.jar:2.4.5]
at org.apache.shardingsphere.core.strategy.route.inline.InlineShardingStrategy.execute(InlineShardingStrategy.java:94) ~[sharding-core-common-4.1.1.jar:4.1.1]
at org.apache.shardingsphere.core.strategy.route.inline.InlineShardingStrategy.doSharding(InlineShardingStrategy.java:76) ~[sharding-core-common-4.1.1.jar:4.1.1]
at org.apache.shardingsphere.core.strategy.route.inline.InlineShardingStrategy.doSharding(InlineShardingStrategy.java:63) ~[sharding-core-common-4.1.1.jar:4.1.1]
at org.apache.shardingsphere.sharding.route.engine.type.standard.ShardingStandardRoutingEngine.routeTables(ShardingStandardRoutingEngine.java:214) ~[sharding-core-route-4.1.1.jar:4.1.1]
at org.apache.shardingsphere.sharding.route.engine.type.standard.ShardingStandardRoutingEngine.route0(ShardingStandardRoutingEngine.java:195) ~[sharding-core-route-4.1.1.jar:4.1.1]
at org.apache.shardingsphere.sharding.route.engine.type.standard.ShardingStandardRoutingEngine.routeByShardingConditionsWithCondition(ShardingStandardRoutingEngine.java:121) ~[sharding-core-route-4.1.1.jar:4.1.1]
at org.apache.shardingsphere.sharding.route.engine.type.standard.ShardingStandardRoutingEngine.routeByShardingConditions(ShardingStandardRoutingEngine.java:115) ~[sharding-core-route-4.1.1.jar:4.1.1]
at org.apache.shardingsphere.sharding.route.engine.type.standard.ShardingStandardRoutingEngine.getDataNodes(ShardingStandardRoutingEngine.java:96) ~[sharding-core-route-4.1.1.jar:4.1.1]
at org.apache.shardingsphere.sharding.route.engine.type.standard.ShardingStandardRoutingEngine.route(ShardingStandardRoutingEngine.java:74) ~[sharding-core-route-4.1.1.jar:4.1.1]
at org.apache.shardingsphere.sharding.route.engine.ShardingRouteDecorator.decorate(ShardingRouteDecorator.java:69) ~[sharding-core-route-4.1.1.jar:4.1.1]
at org.apache.shardingsphere.sharding.route.engine.ShardingRouteDecorator.decorate(ShardingRouteDecorator.java:53) ~[sharding-core-route-4.1.1.jar:4.1.1]
at org.apache.shardingsphere.underlying.route.DataNodeRouter.executeRoute(DataNodeRouter.java:91) ~[shardingsphere-route-4.1.1.jar:4.1.1]
at org.apache.shardingsphere.underlying.route.DataNodeRouter.route(DataNodeRouter.java:76) ~[shardingsphere-route-4.1.1.jar:4.1.1]
at org.apache.shardingsphere.underlying.pluggble.prepare.PreparedQueryPrepareEngine.route(PreparedQueryPrepareEngine.java:54) ~[shardingsphere-pluggable-4.1.1.jar:4.1.1]
at org.apache.shardingsphere.underlying.pluggble.prepare.BasePrepareEngine.executeRoute(BasePrepareEngine.java:96) ~[shardingsphere-pluggable-4.1.1.jar:4.1.1]
at org.apache.shardingsphere.underlying.pluggble.prepare.BasePrepareEngine.prepare(BasePrepareEngine.java:83) ~[shardingsphere-pluggable-4.1.1.jar:4.1.1]
at org.apache.shardingsphere.shardingjdbc.jdbc.core.statement.ShardingPreparedStatement.prepare(ShardingPreparedStatement.java:183) ~[sharding-jdbc-core-4.1.1.jar:4.1.1]
at org.apache.shardingsphere.shardingjdbc.jdbc.core.statement.ShardingPreparedStatement.execute(ShardingPreparedStatement.java:143) ~[sharding-jdbc-core-4.1.1.jar:4.1.1]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) ~[na:na]
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
at java.base/java.lang.reflect.Method.invoke(Method.java:568) ~[na:na]
at org.apache.ibatis.logging.jdbc.PreparedStatementLogger.invoke(PreparedStatementLogger.java:59) ~[mybatis-3.5.7.jar:3.5.7]
at jdk.proxy3/jdk.proxy3.$Proxy95.execute(Unknown Source) ~[na:na]
at org.apache.ibatis.executor.statement.PreparedStatementHandler.query(PreparedStatementHandler.java:64) ~[mybatis-3.5.7.jar:3.5.7]
at org.apache.ibatis.executor.statement.RoutingStatementHandler.query(RoutingStatementHandler.java:79) ~[mybatis-3.5.7.jar:3.5.7]
at org.apache.ibatis.executor.SimpleExecutor.doQuery(SimpleExecutor.java:63) ~[mybatis-3.5.7.jar:3.5.7]
at org.apache.ibatis.executor.BaseExecutor.queryFromDatabase(BaseExecutor.java:325) ~[mybatis-3.5.7.jar:3.5.7]
at org.apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:156) ~[mybatis-3.5.7.jar:3.5.7]
at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:109) ~[mybatis-3.5.7.jar:3.5.7]
at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:89) ~[mybatis-3.5.7.jar:3.5.7]
at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:151) ~[mybatis-3.5.7.jar:3.5.7]
at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:145) ~[mybatis-3.5.7.jar:3.5.7]
at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:140) ~[mybatis-3.5.7.jar:3.5.7]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) ~[na:na]
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
at java.base/java.lang.reflect.Method.invoke(Method.java:568) ~[na:na]
at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:427) ~[mybatis-spring-2.0.6.jar:2.0.6]
at jdk.proxy2/jdk.proxy2.$Proxy65.selectList(Unknown Source) ~[na:na]
at org.mybatis.spring.SqlSessionTemplate.selectList(SqlSessionTemplate.java:224) ~[mybatis-spring-2.0.6.jar:2.0.6]
at org.apache.ibatis.binding.MapperMethod.executeForMany(MapperMethod.java:147) ~[mybatis-3.5.7.jar:3.5.7]
at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:80) ~[mybatis-3.5.7.jar:3.5.7]
at org.apache.ibatis.binding.MapperProxy$PlainMethodInvoker.invoke(MapperProxy.java:145) ~[mybatis-3.5.7.jar:3.5.7]
at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:86) ~[mybatis-3.5.7.jar:3.5.7]
at jdk.proxy2/jdk.proxy2.$Proxy66.getOrderByOrderId(Unknown Source) ~[na:na]
at com.fancv.shardingdemo.service.impl.OrderServiceImpl.getOrderByOrderId(OrderServiceImpl.java:26) ~[classes/:na]
at com.fancv.shardingdemo.controller.OrderController.getOrderInfo(OrderController.java:42) ~[classes/:na]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) ~[na:na]
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
at java.base/java.lang.reflect.Method.invoke(Method.java:568) ~[na:na]
at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:190) ~[spring-web-5.2.8.RELEASE.jar:5.2.8.RELEASE]
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:138) ~[spring-web-5.2.8.RELEASE.jar:5.2.8.RELEASE]
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:105) ~[spring-webmvc-5.2.8.RELEASE.jar:5.2.8.RELEASE]
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:878) ~[spring-webmvc-5.2.8.RELEASE.jar:5.2.8.RELEASE]
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:792) ~[spring-webmvc-5.2.8.RELEASE.jar:5.2.8.RELEASE]
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87) ~[spring-webmvc-5.2.8.RELEASE.jar:5.2.8.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1040) ~[spring-webmvc-5.2.8.RELEASE.jar:5.2.8.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:943) ~[spring-webmvc-5.2.8.RELEASE.jar:5.2.8.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006) ~[spring-webmvc-5.2.8.RELEASE.jar:5.2.8.RELEASE]
搜索资料发现
有人在升级到jdk9 的时候遇到同样问题
通过增加启动参数
--add-opens java.base/java.lang=ALL-UNNAMED
原文信息
会出现以下错误信息:
Exception in thread “main”
java.lang.reflect.InaccessibleObjectException: Unable to make field
private static final long java.lang.Long.serialVersionUID accessible:
module java.base does not “opens java.lang” to unnamed module
@224aed64
at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:207)
at java.base/java.lang.reflect.Field.checkCanSetAccessible(Field.java:171)
at java.base/java.lang.reflect.Field.setAccessible(Field.java:165)
at com.jdojo.intruder.TestManifestAttributes.main(TestManifestAttributes.java:10)
运行时错误表明应用程序无法访问私有静态serialVersionUID,因为java.base模块中的java.lang包未打开。我们先试试–add-opens这个选项:C:\Java9Revealed>java --add-opens java.base/java.lang=ALL-UNNAMED
-jar com.jdojo.intruder\dist\com.jdojo.intruder.jar 输出信息如下:Long.serialVersionUID=4290774380558885855 此命令工作正常,并验证命令行选项是这种情况下的解决方案。
我们使用MANIFEST.MF文件中的Add-Opens属性来修复此错误,如下所示。Manifest-Version: 1.0 Main-Class:
com.jdojo.intruder.TestManifestAttributes Add-Opens:
java.base/java.lang 使用相同的命令重新创建可执行文件JAR并运行它:C:\Java9Revealed>java -jar
com.jdojo.intruder\dist\com.jdojo.intruder.jar 输出结果为:Long.serialVersionUID=4290774380558885855
再次运行项目,查询数据成功
总结:java11升级到java17 是在家中个人电脑,非生产环境,
遇到问题到解决问题大概5小时,因为工程是shareding 研究项目,涉及众多知识点,定位问题时间较长。
疑难:项目本身jdk11 启动没问题,但是升级jdk15 之后报错。
参考资料:https://www.cnblogs.com/IcanFixIt/p/7144366.html
技术交流群: