最近在学习使用springcloudalibaba sentinel时遇到了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 @4785baf8这样的一个bug导致jar包直接无法运行
jdk8是可以直接使用的 因为追求稳定,一般都用的是低版本的springcloud alibaba 所以在用jdk17的环境跑这些东西时就会出现一些奇怪的bug
jdk8 中有关反射相关的功能自从 JDK 9 开始就已经被限制了
经过我在网上查询找到需要在vm options里加上 --add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.base/java.lang.reflect=ALL-UNNAMED
当我以为大公告成的时候
又出现了一些问题在启动成功sentinel之后它不能检测到注册进sentinel的服务出现下面的报错信息
java.lang.IllegalStateException: Cannot load configuration class: com.alibaba.csp.sentinel.dashboard.DashboardApplication
Caused by: org.springframework.cglib.core.CodeGenerationException: java.lang.reflect.InaccessibleObjectException-->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 @74fdb593
Caused by: java.lang.reflect.InaccessibleObjectException: 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 @74fdb593
在我又一番研究后发现需要的是--add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.base/sun.net.util=ALL-UNNAMED
这样启动之后再启动服务就大功告成了 也可以检测到服务了