关于解决module java.base does not “opens java.lang” to unnamed module @333291e3的办法
1.抛出异常
在使用Dubbo和Zookeeper做一个分布式项目时,抛出以下异常:
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2023-07-20 17:00:42.979 ERROR 6920 --- [ main] o.s.boot.SpringApplication : Application run failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'ServiceBean:com.bjpowernode.api.service.PlatBaseInfoService:1.0':
Instantiation of bean failed; nested exception is java.lang.ExceptionInInitializerError
以下是抛出异常的导致因素:
Caused by: java.lang.ExceptionInInitializerError: null
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:na]
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:77) ~[na:na]
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:na]
Caused by: java.lang.IllegalStateException: Failed to create adaptive instance: java.lang.IllegalStateException: Can't create adaptive extension interface
org.apache.dubbo.rpc.Protocol, cause: Unable to make protected final java.lang.Class java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int,java.security.
ProtectionDomain) throws java.lang.ClassFormatError accessible: module java.base does not "opens java.lang" to unnamed module @333291e3
at org.apache.dubbo.common.extension.ExtensionLoader.getAdaptiveExtension(ExtensionLoader.java:486) ~[dubbo-2.7.3.jar:2.7.3]
at org.apache.dubbo.config.ServiceConfig.<clinit>(ServiceConfig.java:119) ~[dubbo-2.7.3.jar:2.7.3]
... 24 common frames omitted
还有2个Caused by,就不列举了。
2.异常原因
导致这个异常发生的原因是使用了JDK17,
3.解决办法
方案一:将JDK版本改为1.8即可!!!
方案二:如果使用JDK17,可以在vm options 增加以下运行参数 。
–add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.base/java.lang.reflect=ALL-UNNAMED
找到 vm options选项的步骤:
在vm options选项中填入:
–add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.base/java.lang.reflect=ALL-UNNAMED文章来源:https://www.toymoban.com/news/detail-718520.html
本人尝试过了,这种方法会抛出新的异常,待解决。(可能是vm options的参数不对)文章来源地址https://www.toymoban.com/news/detail-718520.html
到了这里,关于关于解决module java.base does not “opens java.lang“ to unnamed module @333291e3的办法的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!