当前使用版本(必填,否则不予处理)
springboot == 2.7.14 java == 17 mybatis-plus-boot-starter == 3.5.3.1
该问题是如何引起的?(确定最新版也有问题再提!!!)
在@PostConstruct注解标注的初始化中,进行查询操作,报错opens java.lang.reflect 【如果加了命令行参数--add-opens java.base/java.lang.reflect=ALL-UNNAMED的确可以解决,但是。想的可不可以不加参数也能解决】
因为这个用mybatis的是xml写的,所以测试了删除mybatisplus,直接上mybatis-spring-boot-starter === 2.3.1测试,没有问题,一切正常(mybats不加参数也可以正常运行)
重现步骤(如果有就写完整)
报错信息
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'securityConfig': Unsatisfied dependency expressed through field 'userDetailsService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'userDetailsServiceImpl': Unsatisfied dependency expressed through field 'userService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'sysUserServiceImpl': Unsatisfied dependency expressed through field 'configService'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sysConfigServiceImpl': Invocation of init method 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 @443118b0
The error may exist in file [D:\xxxxxxxxxxx\private-work - java17\target\classes\mapper\system\SysConfigMapper.xml]
The error may involve com.work.project.modules.system.mapper.SysConfigMapper.selectConfigList
The error occurred while executing a query
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 @443118b0
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.resolveFieldValue(AutowiredAnnotationBeanPostProcessor.java:662)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:642)
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:119)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessProperties(AutowiredAnnotationBeanPostProcessor.java:399)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1431)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:619)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542)
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:955)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:921)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:583)
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:147)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:731)
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:408)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:307)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1303)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1292)
at com.work.ProjectApplication.main(ProjectApplication.java:10)
Comment From: nieqiurong
看着没啥问题,提供一下你的复现工程.
Comment From: gffguo
@nieqiurong 嗯~对不起,我今天又·尝试了一下,如果新建项目,直接mybatisplus,的确没有问题;
可能是我个性化这个“若依”框架,改出来的问题;但是我实在还是没有查出来问题,为什么我再这个框架中,java8使用plus组件没问题,这个开源框架下,java17用plus就会这样报错(实验的mybatis也没事)我实在是看不明白为什么了。。如果您对这个问题感兴趣,可以下载下来看一下。。;git地址https://gitee.com/gffguo/demo.git
Comment From: nieqiurong
这工程很有意义,我尝试修复一下.
@nieqiurong 嗯~对不起,我今天又·尝试了一下,如果新建项目,直接mybatisplus,的确没有问题;
可能是我个性化这个“若依”框架,改出来的问题;但是我实在还是没有查出来问题,为什么我再这个框架中,java8使用plus组件没问题,这个开源框架下,java17用plus就会这样报错(实验的mybatis也没事)我实在是看不明白为什么了。。如果您对这个问题感兴趣,可以下载下来看一下。。;git地址https://gitee.com/gffguo/demo.git
这工程很有意义,我尝试修复一下.
Comment From: gffguo
非常感谢,我实在是看不出来哪出问题了。无法帮助你更好的定位了
Comment From: nieqiurong
非常感谢,我实在是看不出来哪出问题了。无法帮助你更好的定位了
下载解压至你本地maven仓库,修改mybatis-plus版本至3.5.3.3-SNAPSHOT试试.
链接:https://pan.baidu.com/s/119nbwlHk6h8W92PPlYXotA 提取码:mgp6
Comment From: gffguo
好的,我现在试试
Comment From: gffguo
@nieqiurong 大佬!非常非常感谢,没问题了,你给的这个版本解决了我这个问题
Comment From: nieqiurong