做大作业时,SpringBoot后端连接数据库运行后,测试所有的接口都返回500,报错信息如下
SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@61fa2ac1] was not registered for synchronization because synchronization is not active
JDBC Connection [HikariProxyConnection@1189038771 wrapping com.mysql.cj.jdbc.ConnectionImpl@634a8d8f] will not be managed by Spring
==> Preparing: SELECT id,name,amount FROM account
Closing non transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@61fa2ac1]
2022-07-03 14:29:51.015 ERROR 22332 --- [nio-8080-exec-6] 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 protected java.lang.reflect.InvocationHandler java.lang.reflect.Proxy.h accessible: module java.base does not "opens java.lang.reflect" to unnamed module @5119fb47
The error may exist in com/nju/edu/erp/dao/AccountDao.java (best guess)
The error may involve defaultParameterMap
The error occurred while setting parameters
SQL: SELECT id,name,amount FROM account
Cause: java.lang.reflect.InaccessibleObjectException: Unable to make field protected java.lang.reflect.InvocationHandler java.lang.reflect.Proxy.h accessible: module java.base does not "opens java.lang.reflect" to unnamed module @5119fb47] with root cause
相关的配置情况:
- 数据库是本地MySQL数据库,版本为:8.0.28
- JDBC连接数据库的驱动jar包版本是:mysql-connector-java:8.0.27
- jdk版本:1.7
在网上搜索了大量的资料,很难搜到完全一致的报错,而类似的报错都认为是数据库配置的问题,或者是mapper.xml文件中出错。但是经过仔细检查,这些都是正确的。
最后,经过同学和助教的建议,将jdk版本换成1.8就解决了。
简单陈述一下过程:
1、下载安装新版本jdk,记住修改环境变量 JAVA_HOME
2、加入新版本的jdk,并且替换项目的jdk版本