当前位置:   article > 正文

Caused by: java.lang.reflect.InaccessibleObjectException: Unable to make protected final java.lang.C

caused by: java.lang.reflect.inaccessibleobjectexception: unable to make fie

最近在学习JDK17的时候遇到这么一个问题,springBoot启动失败,日志如下:

  1. Exception in thread "main" java.lang.IllegalArgumentException: Unable to instantiate factory class [com.ctrip.framework.apollo.spring.boot.ApolloApplicationContextInitializer] for factory type [org.springframework.context.ApplicationContextInitializer]
  2. at org.springframework.core.io.support.SpringFactoriesLoader$FailureHandler.lambda$throwing$0(SpringFactoriesLoader.java:650)
  3. at org.springframework.core.io.support.SpringFactoriesLoader$FailureHandler.lambda$handleMessage$3(SpringFactoriesLoader.java:674)
  4. at org.springframework.core.io.support.SpringFactoriesLoader.instantiateFactory(SpringFactoriesLoader.java:231)
  5. at org.springframework.core.io.support.SpringFactoriesLoader.load(SpringFactoriesLoader.java:206)
  6. at org.springframework.core.io.support.SpringFactoriesLoader.load(SpringFactoriesLoader.java:160)
  7. at org.springframework.boot.SpringApplication.getSpringFactoriesInstances(SpringApplication.java:459)
  8. at org.springframework.boot.SpringApplication.getSpringFactoriesInstances(SpringApplication.java:455)
  9. at org.springframework.boot.SpringApplication.<init>(SpringApplication.java:273)
  10. at org.springframework.boot.SpringApplication.<init>(SpringApplication.java:252)
  11. at com.zzz.train.business.BusinessApplication.main(BusinessApplication.java:20)
  12. Caused by: java.lang.reflect.InvocationTargetException
  13. at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
  14. at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:77)
  15. at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
  16. at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:499)
  17. at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:480)
  18. at org.springframework.core.io.support.SpringFactoriesLoader$FactoryInstantiator.instantiate(SpringFactoriesLoader.java:381)
  19. at org.springframework.core.io.support.SpringFactoriesLoader.instantiateFactory(SpringFactoriesLoader.java:228)
  20. ... 7 more
  21. Caused by: com.ctrip.framework.apollo.exceptions.ApolloConfigException: Unable to load instance for com.ctrip.framework.apollo.spring.config.ConfigPropertySourceFactory!
  22. at com.ctrip.framework.apollo.spring.util.SpringInjector.getInstance(SpringInjector.java:40)
  23. at com.ctrip.framework.apollo.spring.boot.ApolloApplicationContextInitializer.<init>(ApolloApplicationContextInitializer.java:48)
  24. ... 14 more
  25. Caused by: com.ctrip.framework.apollo.exceptions.ApolloConfigException: Unable to initialize Apollo Spring Injector!
  26. at com.ctrip.framework.apollo.spring.util.SpringInjector.getInjector(SpringInjector.java:24)
  27. at com.ctrip.framework.apollo.spring.util.SpringInjector.getInstance(SpringInjector.java:37)
  28. ... 15 more
  29. Caused by: com.google.common.util.concurrent.ExecutionError: java.lang.ExceptionInInitializerError
  30. at com.google.common.cache.LocalCache$Segment.get(LocalCache.java:2201)
  31. at com.google.common.cache.LocalCache.get(LocalCache.java:3937)
  32. at com.google.common.cache.LocalCache.getOrLoad(LocalCache.java:3941)
  33. at com.google.common.cache.LocalCache$LocalLoadingCache.get(LocalCache.java:4824)
  34. at com.google.common.cache.LocalCache$LocalLoadingCache.getUnchecked(LocalCache.java:4830)
  35. at com.google.inject.internal.FailableCache.get(FailableCache.java:48)
  36. at com.google.inject.internal.ConstructorInjectorStore.get(ConstructorInjectorStore.java:50)
  37. at com.google.inject.internal.ConstructorBindingImpl.initialize(ConstructorBindingImpl.java:138)
  38. at com.google.inject.internal.InjectorImpl.initializeBinding(InjectorImpl.java:536)
  39. at com.google.inject.internal.AbstractBindingProcessor$Processor$1.run(AbstractBindingProcessor.java:160)
  40. at com.google.inject.internal.ProcessedBindingData.initializeBindings(ProcessedBindingData.java:44)
  41. at com.google.inject.internal.InternalInjectorCreator.initializeStatically(InternalInjectorCreator.java:123)
  42. at com.google.inject.internal.InternalInjectorCreator.build(InternalInjectorCreator.java:107)
  43. at com.google.inject.Guice.createInjector(Guice.java:99)
  44. at com.google.inject.Guice.createInjector(Guice.java:73)
  45. at com.google.inject.Guice.createInjector(Guice.java:62)
  46. at com.ctrip.framework.apollo.spring.util.SpringInjector.getInjector(SpringInjector.java:22)
  47. ... 16 more
  48. Caused by: java.lang.ExceptionInInitializerError
  49. at com.google.inject.internal.cglib.reflect.$FastClass$Generator.getProtectionDomain(FastClass.java:73)
  50. at com.google.inject.internal.cglib.core.$AbstractClassGenerator.create(AbstractClassGenerator.java:206)
  51. at com.google.inject.internal.cglib.reflect.$FastClass$Generator.create(FastClass.java:65)
  52. at com.google.inject.internal.BytecodeGen.newFastClassForMember(BytecodeGen.java:252)
  53. at com.google.inject.internal.BytecodeGen.newFastClassForMember(BytecodeGen.java:203)
  54. at com.google.inject.internal.DefaultConstructionProxyFactory.create(DefaultConstructionProxyFactory.java:53)
  55. at com.google.inject.internal.ProxyFactory.create(ProxyFactory.java:158)
  56. at com.google.inject.internal.ConstructorInjectorStore.createConstructor(ConstructorInjectorStore.java:90)
  57. at com.google.inject.internal.ConstructorInjectorStore.access$000(ConstructorInjectorStore.java:29)
  58. at com.google.inject.internal.ConstructorInjectorStore$1.create(ConstructorInjectorStore.java:37)
  59. at com.google.inject.internal.ConstructorInjectorStore$1.create(ConstructorInjectorStore.java:33)
  60. at com.google.inject.internal.FailableCache$1.load(FailableCache.java:37)
  61. at com.google.common.cache.LocalCache$LoadingValueReference.loadFuture(LocalCache.java:3527)
  62. at com.google.common.cache.LocalCache$Segment.loadSync(LocalCache.java:2319)
  63. at com.google.common.cache.LocalCache$Segment.lockedGetOrLoad(LocalCache.java:2282)
  64. at com.google.common.cache.LocalCache$Segment.get(LocalCache.java:2197)
  65. ... 32 more
  66. 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 @d35dea7
  67. at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:354)
  68. at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:297)
  69. at java.base/java.lang.reflect.Method.checkCanSetAccessible(Method.java:199)
  70. at java.base/java.lang.reflect.Method.setAccessible(Method.java:193)
  71. at com.google.inject.internal.cglib.core.$ReflectUtils$1.run(ReflectUtils.java:52)
  72. at java.base/java.security.AccessController.doPrivileged(AccessController.java:318)
  73. at com.google.inject.internal.cglib.core.$ReflectUtils.<clinit>(ReflectUtils.java:42)
  74. ... 48 more
  75. Process finished with exit code 1

原因:这是由于 JDK 8 中有关反射相关的功能自从 JDK 9 开始就已经被限制了,为了兼容原先的版本,需要在运行项目时添加 --add-opens java.base/java.lang=ALL-UNNAMED 选项来开启这种默认不被允许的行为。

解决方案:

结果:

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/天景科技苑/article/detail/760458
推荐阅读
相关标签
  

闽ICP备14008679号