Issue
My project is a SpringBoot application, which contains one java module. This module does not open
any of its packages.
module-info.java
module my.somewhere
{
requires spring.core;
requires spring.context;
requires spring.boot;
// and so on
}
The app runs as expected when called from command line mvn clean spring-boot:run
.
But when I try to start it from the main method of the SpringBootApplication, the following error appears in console: java.lang.IllegalAccessException: module my.somewhere does not open my.somewhere.abc to module spring.core
(see detailed stack below).
It looks reasonable to have something opened to Spring due to its reflection operations, but I wonder why maven manages to run it without problems.
Please, help me to understand how to make the app run similarly from Maven 3.6.1
and from IntelliJ IDEA 2019.3
.
Detailed stack:
org.springframework.cglib.core.CodeGenerationException: java.lang.IllegalAccessException-->module my.somewhere does not open my.somewhere.abc to module spring.core
at [email protected]/org.springframework.cglib.core.ReflectUtils.defineClass(ReflectUtils.java:514) ~[spring-core-5.2.4.RELEASE.jar:na]
at [email protected]/org.springframework.cglib.core.AbstractClassGenerator.generate(AbstractClassGenerator.java:363) ~[spring-core-5.2.4.RELEASE.jar:na]
at [email protected]/org.springframework.cglib.proxy.Enhancer.generate(Enhancer.java:582) ~[spring-core-5.2.4.RELEASE.jar:na]
at [email protected]/org.springframework.cglib.core.AbstractClassGenerator$ClassLoaderData$3.apply(AbstractClassGenerator.java:110) ~[spring-core-5.2.4.RELEASE.jar:na]
at [email protected]/org.springframework.cglib.core.AbstractClassGenerator$ClassLoaderData$3.apply(AbstractClassGenerator.java:108) ~[spring-core-5.2.4.RELEASE.jar:na]
at [email protected]/org.springframework.cglib.core.internal.LoadingCache$2.call(LoadingCache.java:54) ~[spring-core-5.2.4.RELEASE.jar:na]
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264) ~[na:na]
at [email protected]/org.springframework.cglib.core.internal.LoadingCache.createEntry(LoadingCache.java:61) ~[spring-core-5.2.4.RELEASE.jar:na]
at [email protected]/org.springframework.cglib.core.internal.LoadingCache.get(LoadingCache.java:34) ~[spring-core-5.2.4.RELEASE.jar:na]
at [email protected]/org.springframework.cglib.core.AbstractClassGenerator$ClassLoaderData.get(AbstractClassGenerator.java:134) ~[spring-core-5.2.4.RELEASE.jar:na]
at [email protected]/org.springframework.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:319) ~[spring-core-5.2.4.RELEASE.jar:na]
at [email protected]/org.springframework.cglib.proxy.Enhancer.createHelper(Enhancer.java:569) ~[spring-core-5.2.4.RELEASE.jar:na]
at [email protected]/org.springframework.cglib.proxy.Enhancer.createClass(Enhancer.java:416) ~[spring-core-5.2.4.RELEASE.jar:na]
at [email protected]/org.springframework.context.annotation.ConfigurationClassEnhancer.createClass(ConfigurationClassEnhancer.java:137) ~[spring-context-5.2.4.RELEASE.jar:na]
at [email protected]/org.springframework.context.annotation.ConfigurationClassEnhancer.enhance(ConfigurationClassEnhancer.java:109) ~[spring-context-5.2.4.RELEASE.jar:na]
at [email protected]/org.springframework.context.annotation.ConfigurationClassPostProcessor.enhanceConfigurationClasses(ConfigurationClassPostProcessor.java:423) ~[spring-context-5.2.4.RELEASE.jar:na]
at [email protected]/org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanFactory(ConfigurationClassPostProcessor.java:257) ~[spring-context-5.2.4.RELEASE.jar:na]
at [email protected]/org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:286) ~[spring-context-5.2.4.RELEASE.jar:na]
at [email protected]/org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:130) ~[spring-context-5.2.4.RELEASE.jar:na]
at [email protected]/org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:706) ~[spring-context-5.2.4.RELEASE.jar:na]
at [email protected]/org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:532) ~[spring-context-5.2.4.RELEASE.jar:na]
at [email protected]/org.springframework.boot.web.reactive.context.ReactiveWebServerApplicationContext.refresh(ReactiveWebServerApplicationContext.java:66) ~[spring-boot-2.2.5.RELEASE.jar:na]
at [email protected]/org.springframework.boot.SpringApplication.refresh(SpringApplication.java:747) ~[spring-boot-2.2.5.RELEASE.jar:na]
at [email protected]/org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) ~[spring-boot-2.2.5.RELEASE.jar:na]
at [email protected]/org.springframework.boot.SpringApplication.run(SpringApplication.java:315) ~[spring-boot-2.2.5.RELEASE.jar:na]
at [email protected]/org.springframework.boot.SpringApplication.run(SpringApplication.java:1226) ~[spring-boot-2.2.5.RELEASE.jar:na]
at [email protected]/org.springframework.boot.SpringApplication.run(SpringApplication.java:1215) ~[spring-boot-2.2.5.RELEASE.jar:na]
at [email protected]/my.somewhere.MyApplication.main(MyApplication.java:11) ~[classes/:na]
Caused by: java.lang.IllegalAccessException: module my.somewhere does not open my.somewhere.abc to module spring.core
at java.base/java.lang.invoke.MethodHandles.privateLookupIn(MethodHandles.java:202) ~[na:na]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:na]
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
at java.base/java.lang.reflect.Method.invoke(Method.java:566) ~[na:na]
at [email protected]/org.springframework.cglib.core.ReflectUtils.defineClass(ReflectUtils.java:508) ~[spring-core-5.2.4.RELEASE.jar:na]
... 27 common frames omitted
Solution
Because if you run it with mvn clean spring-boot:run
all your classes and JARs are in the classpath not in the module-path.
So there is no module system when running it with the maven plugin or as executable JAR.
Answered By - Simon Martinelli
Answer Checked By - Dawn Plyler (JavaFixing Volunteer)