The meaning of life is to explore the world

Java spring-boot configuration error reflect.InaccessibleObjectException

Posted on By Jason Liu

Error message:

17:12:28.224 ERROR [com.Company.program.boot.programApplicationLauncher.main()] o.s.boot.SpringApplication - Application startup failed
java.lang.IllegalStateException: Cannot load configuration class: com.Company.program.boot.config.ApplicationConfiguration
 at org.springframework.context.annotation.ConfigurationClassPostProcessor.enhanceConfigurationClasses(ConfigurationClassPostProcessor.java:395) ~[spring-context-4.1.6.RELEASE.jar:4.1.6.RELEASE]
 ......
 at java.base/java.lang.Thread.run(Thread.java:833) ~[na:na]
Caused by: java.lang.ExceptionInInitializerError: null
 at org.springframework.cglib.core.KeyFactory$Generator.generateClass(KeyFactory.java:166) ~[spring-core-4.1.6.RELEASE.jar:4.1.6.RELEASE]
 ......
 ... 17 common frames omitted
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 @43905a1d
 at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:354) ~[na:na]
 ......
 ... 28 common frames omitted

Root cause:
     A warning in JDK-11 has become an error in JDK-17

Solution:
     In Eclipse Maven run configuration, JRE tab, change JDK-17 to JDK-11

The warning after the fix:

WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.springframework.cglib.core.ReflectUtils$2 (file:/C:/Users/jason.liu/.m2/repository/org/springframework/spring-core/4.1.6.RELEASE/spring-core-4.1.6.RELEASE.jar) to method java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int,java.security.ProtectionDomain)
WARNING: Please consider reporting this to the maintainers of org.springframework.cglib.core.ReflectUtils$2
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release