Zakariyya / blog

https://zakariyya.github.io/blog/
6 stars 1 forks source link

module java.base does not "opens java.lang" to unnamed module #167

Open Zakariyya opened 7 months ago

Zakariyya commented 7 months ago
org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.PersistenceException: 
### Error updating 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 @5e0826e7
### The error may exist in com/jsh/erp/system/mapper/LogMapper.java (best guess)
### The error may involve com.jsh.erp.system.mapper.LogMapper.insert-Inline
### The error occurred while setting parameters
### SQL: INSERT INTO log (user_id, model, operation, client_ip, status, content, tenant_id) VALUES (?, ?, ?, ?, ?, ?, ?)
### 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 @5e0826e7

是由于 Java 9+ 中的模块化系统所引起的权限限制问题。错误提示表明,在访问 Java 语言中的某些字段时,出现了无法访问的异常,这可能是由于模块化系统中的限制所致。

针对你的错误信息,似乎是在 MyBatis 操作数据库时出现的问题。具体来说,是在执行一个涉及日志表插入的操作时出错。错误提示中提到了插入日志表时的字段以及可能的原因,其中涉及到了对 java.lang.Number 类中的 serialVersionUID 字段进行访问,但由于模块化系统的限制,导致无法访问该字段,从而引发了异常。

我还不知道有什么办法能直接优化这个问题,只能抄网上的办法,但很明显,只是绕开,不是直接解决:

## 添加jvm启动项
--add-opens java.base/java.lang=ALL-UNNAMED