Skip to content

Java 启动参数

  1. 在 Java 启动时增加参数以解决相应的问题

--add-opens java.base/java.lang=ALL-UNNAMED

  1. 使用 JDK 17/22 等,启动 Nacos 2.4.1 将会出现以下异常
shell
java.lang.reflect.InaccessibleObjectException: Unable to make field private byte java.lang.StackTraceElement.format accessible: module java.base does not "opens java.lang" to unnamed module @459e9125
	at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:354)
	at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:297)
	at java.base/java.lang.reflect.Field.checkCanSetAccessible(Field.java:178)
	at java.base/java.lang.reflect.Field.setAccessible(Field.java:172)
	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$$fca2a318.CGLIB$strongAgreementProtocol$0(<generated>)
	at com.alibaba.nacos.core.distributed.ConsistencyConfiguration$$EnhancerBySpringCGLIB$$fca2a318$$FastClassBySpringCGLIB$$f153a6e1.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$$fca2a318.strongAgreementProtocol(<generated>)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:568)
	at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154)
	at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:648)
	at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:633)
	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: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:233)
	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:1186)
	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:539)
	at java.base/java.util.concurrent.FutureTask.runAndReset(FutureTask.java:305)
	at java.base/java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:305)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
	at java.base/java.lang.Thread.run(Thread.java:833)