I have a SpringBoot application that was developed with JDK8 and was now ported to JDK11. I get the following exception at startup:
ERROR SpringApplication: Application run failed org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'groovyMarkupConfigurer' defined in class path resource [org/springframework/boot/autoconfigure/groovy/template/GroovyTemplateAutoConfiguration$GroovyMarkupConfiguration.class]: Invocation of init method failed; nested exception is java.lang.reflect.InaccessibleObjectException: Unable to make jdk.internal.loader.ClassLoaders$AppClassLoader(jdk.internal.loader.ClassLoaders$PlatformClassLoader,jdk.internal.loader.URLClassPath) accessible: module java.base does not "opens jdk.internal.loader" to unnamed module @2e3967ea at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1778) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:593) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:515) at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:320) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:845) at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:877) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:549) at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:141) at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:744) at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:391) at org.springframework.boot.SpringApplication.run(SpringApplication.java:312) at org.springframework.boot.builder.SpringApplicationBuilder.run(SpringApplicationBuilder.java:140) at de.ff.jf.bftag.alarmmonitor.Main.main(Main.java:38) Caused by: java.lang.reflect.InaccessibleObjectException: Unable to make jdk.internal.loader.ClassLoaders$AppClassLoader(jdk.internal.loader.ClassLoaders$PlatformClassLoader,jdk.internal.loader.URLClassPath) accessible: module java.base does not "opens jdk.internal.loader" to unnamed module @2e3967ea at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:340) at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:280) at java.base/java.lang.reflect.Constructor.checkCanSetAccessible(Constructor.java:189) at java.base/java.lang.reflect.Constructor.setAccessible(Constructor.java:182) at org.codehaus.groovy.reflection.CachedConstructor$1.run(CachedConstructor.java:44) at java.base/java.security.AccessController.doPrivileged(Native Method) at org.codehaus.groovy.reflection.CachedConstructor.<init>(CachedConstructor.java:42) at org.codehaus.groovy.reflection.CachedClass$2.initValue(CachedClass.java:79) at org.codehaus.groovy.reflection.CachedClass$2.initValue(CachedClass.java:69) at org.codehaus.groovy.util.LazyReference.getLocked(LazyReference.java:49) at org.codehaus.groovy.util.LazyReference.get(LazyReference.java:36) at org.codehaus.groovy.reflection.CachedClass.getConstructors(CachedClass.java:268) at groovy.lang.MetaClassImpl.<init>(MetaClassImpl.java:218) at groovy.lang.MetaClassImpl.<init>(MetaClassImpl.java:228) at groovy.lang.MetaClassRegistry$MetaClassCreationHandle.createNormalMetaClass(MetaClassRegistry.java:171) at groovy.lang.MetaClassRegistry$MetaClassCreationHandle.createWithCustomLookup(MetaClassRegistry.java:161) at groovy.lang.MetaClassRegistry$MetaClassCreationHandle.create(MetaClassRegistry.java:144) at org.codehaus.groovy.reflection.ClassInfo.getMetaClassUnderLock(ClassInfo.java:253) at org.codehaus.groovy.reflection.ClassInfo.getMetaClass(ClassInfo.java:285) at org.codehaus.groovy.reflection.ClassInfo.getMetaClass(ClassInfo.java:295) at org.codehaus.groovy.runtime.metaclass.MetaClassRegistryImpl.getMetaClass(MetaClassRegistryImpl.java:261) at org.codehaus.groovy.runtime.InvokerHelper.getMetaClass(InvokerHelper.java:873) at org.codehaus.groovy.runtime.InvokerHelper.invokePojoMethod(InvokerHelper.java:906) at org.codehaus.groovy.runtime.InvokerHelper.invokeMethod(InvokerHelper.java:898) at org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.castToBoolean(DefaultTypeTransformation.java:185) at org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.booleanUnbox(DefaultTypeTransformation.java:74) at org.codehaus.groovy.control.customizers.ASTTransformationCustomizer.findASTTranformationClass(ASTTransformationCustomizer.groovy:209) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.base/java.lang.reflect.Method.invoke(Method.java:566) at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:93) at org.codehaus.groovy.runtime.callsite.StaticMetaMethodSite$StaticMetaMethodSiteNoUnwrapNoCoerce.invoke(StaticMetaMethodSite.java:151) at org.codehaus.groovy.runtime.callsite.StaticMetaMethodSite.callStatic(StaticMetaMethodSite.java:102) at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallStatic(CallSiteArray.java:56) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callStatic(AbstractCallSite.java:194) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callStatic(AbstractCallSite.java:214) at org.codehaus.groovy.control.customizers.ASTTransformationCustomizer.findPhase(ASTTransformationCustomizer.groovy:226) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.base/java.lang.reflect.Method.invoke(Method.java:566) at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:93) at org.codehaus.groovy.runtime.callsite.StaticMetaMethodSite$StaticMetaMethodSiteNoUnwrapNoCoerce.invoke(StaticMetaMethodSite.java:151) at org.codehaus.groovy.runtime.callsite.StaticMetaMethodSite.callStatic(StaticMetaMethodSite.java:102) at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallStatic(CallSiteArray.java:56) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callStatic(AbstractCallSite.java:194) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callStatic(AbstractCallSite.java:214) at org.codehaus.groovy.control.customizers.ASTTransformationCustomizer.<init>(ASTTransformationCustomizer.groovy:180) at org.codehaus.groovy.control.customizers.ASTTransformationCustomizer.<init>(ASTTransformationCustomizer.groovy:188) at groovy.text.markup.MarkupTemplateEngine.<init>(MarkupTemplateEngine.java:94) at org.springframework.web.servlet.view.groovy.GroovyMarkupConfigurer.createTemplateEngine(GroovyMarkupConfigurer.java:159) at org.springframework.web.servlet.view.groovy.GroovyMarkupConfigurer.afterPropertiesSet(GroovyMarkupConfigurer.java:152) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1837) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1774) ... 15 more
Here is my pom.xml:
<dependencies> <dependency> <groupId>org.jxmapviewer</groupId> <artifactId>jxmapviewer2</artifactId> <version>2.4</version> </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.12</version> <scope>test</scope> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> <version>2.2.1.RELEASE</version> <exclusions> <exclusion> <groupId>ch.qos.logback</groupId> <artifactId>logback-classic</artifactId> </exclusion> </exclusions> </dependency> </dependencies>
I have tried SpringWebStarter from 2.1.8 up to 2.2.1, I am always getting the same error.
I cannot use JDK8 again, since the computer has been updated from Windows 7 to Windows 10 and I am not willed to register at Oracle to download the JDK8 😉
Has someone experienced this issue or does anyone have an idea how to solve this?
Advertisement
Answer
Your error is related to Java module system:
java.lang.reflect.InaccessibleObjectException: Unable to make jdk.internal.loader.ClassLoaders$AppClassLoader(jdk.internal.loader.ClassLoaders$PlatformClassLoader,jdk.internal.loader.URLClassPath) accessible: module java.base does not “opens jdk.internal.loader” to unnamed module @2e3967ea
Judging from the stack trace this is caused by Groovy so either your are using an old Groovy version that doesn’t support JDK 9 or running code that imports jdk.internal.loader
without declaring proper Java module access.
I’d start by checking that you have recent Groovy dependencies but a quick workaround would be to run the JVM with:
--add-opens java.base/jdk.internal.loader=ALL-UNNAMED