在本地jdk21.0.4环境下启动Nacos Server 2.4.1时报了“module java.base does not “opens java.lang” to unnamed module @2be94b0f”错误,具体如下:
这个问题之前在Eclipse、IDEA、Tomcat等使用过程也遇到过,是因为JDK 9及以上版本中引入Java Platform Module System强制执行封装边界,并且只允许明确导出的包进行访问,默认情况下java.lang和其他一些核心包都不会向unnamed模块开放,所以在JDK 11和JDK 17环境下应该也会有这个问题。
解决办法可以在startup.sh中加上“JAVA_OPT=”${JAVA_OPT} –add-opens java.base/java.lang=ALL-UNNAMED””参数即可,或者等待官方修复,或者降到Nacos Server 2.4.0.1。
最后附上错误日志。
java.lang.reflect.InaccessibleObjectException: Unable to make field private java.lang.String java.lang.StackTraceElement.classLoaderName accessible: module java.base does not "opens java.lang" to unnamed module @2be94b0f
at java.base/java.lang.reflect.AccessibleObject.throwInaccessibleObjectException(AccessibleObject.java:391)
at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:367)
at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:315)
at java.base/java.lang.reflect.Field.checkCanSetAccessible(Field.java:183)
at java.base/java.lang.reflect.Field.setAccessible(Field.java:177)
at com.caucho.hessian.io.JavaDeserializer.getFieldMap(JavaDeserializer.java:363)
at com.caucho.hessian.io.JavaDeserializer.<init>(JavaDeserializer.java:72)
at com.caucho.hessian.io.StackTraceElementDeserializer.<init>(StackTraceElementDeserializer.java:60)
at com.caucho.hessian.io.ContextSerializerFactory.<clinit>(ContextSerializerFactory.java:481)
at com.caucho.hessian.io.SerializerFactory.<init>(SerializerFactory.java:143)
at com.caucho.hessian.io.SerializerFactory.<init>(SerializerFactory.java:137)
at com.alibaba.nacos.consistency.serialize.NacosHessianSerializerFactory.<init>(NacosHessianSerializerFactory.java:59)
at com.alibaba.nacos.consistency.serialize.HessianSerializer.<init>(HessianSerializer.java:41)
at com.alibaba.nacos.consistency.SerializeFactory.<clinit>(SerializeFactory.java:39)
at com.alibaba.nacos.core.distributed.raft.JRaftProtocol.<init>(JRaftProtocol.java:100)
at com.alibaba.nacos.core.distributed.ConsistencyConfiguration.lambda$strongAgreementProtocol$0(ConsistencyConfiguration.java:40)
at com.alibaba.nacos.core.distributed.ConsistencyConfiguration.getProtocol(ConsistencyConfiguration.java:53)
at com.alibaba.nacos.core.distributed.ConsistencyConfiguration.strongAgreementProtocol(ConsistencyConfiguration.java:40)
at com.alibaba.nacos.core.distributed.ConsistencyConfiguration$$EnhancerBySpringCGLIB$$ccf67822.CGLIB$strongAgreementProtocol$0(<generated>)
at com.alibaba.nacos.core.distributed.ConsistencyConfiguration$$EnhancerBySpringCGLIB$$ccf67822$$FastClassBySpringCGLIB$$c25db4ab.invoke(<generated>)
at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:244)
at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:331)
at com.alibaba.nacos.core.distributed.ConsistencyConfiguration$$EnhancerBySpringCGLIB$$ccf67822.strongAgreementProtocol(<generated>)
at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
at java.base/java.lang.reflect.Method.invoke(Method.java:580)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154)
at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:641)
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:626)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1352)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1195)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:582)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542)
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:336)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:334)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:234)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveNamedBean(DefaultListableBeanFactory.java:1284)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveNamedBean(DefaultListableBeanFactory.java:1245)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveBean(DefaultListableBeanFactory.java:494)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBean(DefaultListableBeanFactory.java:349)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBean(DefaultListableBeanFactory.java:342)
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1189)
at com.alibaba.nacos.sys.utils.ApplicationUtils.getBeanIfExist(ApplicationUtils.java:155)
at com.alibaba.nacos.core.distributed.ProtocolManager.initCPProtocol(ProtocolManager.java:124)
at com.alibaba.nacos.core.distributed.ProtocolManager.getCpProtocol(ProtocolManager.java:85)
at com.alibaba.nacos.naming.cluster.ServerStatusManager.hasLeader(ServerStatusManager.java:70)
at com.alibaba.nacos.naming.cluster.ServerStatusManager.refreshServerStatus(ServerStatusManager.java:62)
at com.alibaba.nacos.naming.cluster.ServerStatusManager.access$000(ServerStatusManager.java:37)
at com.alibaba.nacos.naming.cluster.ServerStatusManager$ServerStatusUpdater.run(ServerStatusManager.java:92)
at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:572)
at java.base/java.util.concurrent.FutureTask.runAndReset(FutureTask.java:358)
at java.base/java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:305)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1144)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:642)
at java.base/java.lang.Thread.run(Thread.java:1583)
历史上的今天:
展开阅读全文