我有一个具有有趣模块结构的应用程序:它包含自己的模块,这些模块又包含jpms模块:
aplication (dependencies: spring.boot, spring.core, etc...)
|
+--module1 (dependencies: ...)
|
+--module2 (dependencies: ...)
module layer
。在这种层次结构中,模块可以从父模块(应用程序)访问类。ApplicationContext
,并且它们具有对应的子父关系。Spring在应用程序内部正常工作,但是由于另一个模块层而无法访问子模块内部的类。 Spring通过扫描通过SpringApplicationBuilder#sources传递的源类上的注释来启动其工作,但是由于所描述的问题而不能。我现在看到的错误是:
java.lang.IllegalStateException: Cannot load configuration class: myapplication.module1.Module1
at org.springframework.context.annotation.ConfigurationClassPostProcessor.enhanceConfigurationClasses(ConfigurationClassPostProcessor.java:413) ~[spring-context-5.1.4.RELEASE.jar:?]
at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanFactory(ConfigurationClassPostProcessor.java:253) ~[spring-context-5.1.4.RELEASE.jar:?]
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:286) ~[spring-context-5.1.4.RELEASE.jar:?]
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:130) ~[spring-context-5.1.4.RELEASE.jar:?]
at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:691) ~[spring-context-5.1.4.RELEASE.jar:?]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:528) ~[spring-context-5.1.4.RELEASE.jar:?]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:775) [spring-boot-2.1.2.RELEASE.jar:?]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) [spring-boot-2.1.2.RELEASE.jar:?]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:316) [spring-boot-2.1.2.RELEASE.jar:?]
at myapplication.module1.Module1.start(Module1.java:25) [classes/:?]
at myapplication.launcher.graph.ModuleNode.start(ModuleNode.java:156) [classes/:?]
at myapplication.launcher.graph.ModuleGraph.startModuleRecursively(ModuleGraph.java:49) [classes/:?]
at java.util.ArrayList.forEach(ArrayList.java:1540) [?:?]
at myapplication.launcher.graph.ModuleGraph.startAllModules(ModuleGraph.java:42) [classes/:?]
at myapplication.launcher.Launcher.main(Launcher.java:49) [classes/:?]
Caused by: org.springframework.cglib.core.CodeGenerationException: java.lang.IllegalAccessException-->module spring.core does not read module myapplication.module1
at org.springframework.cglib.core.ReflectUtils.defineClass(ReflectUtils.java:503) ~[spring-core-5.1.4.RELEASE.jar:?]
at org.springframework.cglib.core.AbstractClassGenerator.generate(AbstractClassGenerator.java:363) ~[spring-core-5.1.4.RELEASE.jar:?]
at org.springframework.cglib.proxy.Enhancer.generate(Enhancer.java:582) ~[spring-core-5.1.4.RELEASE.jar:?]
at org.springframework.cglib.core.AbstractClassGenerator$ClassLoaderData$3.apply(AbstractClassGenerator.java:110) ~[spring-core-5.1.4.RELEASE.jar:?]
at org.springframework.cglib.core.AbstractClassGenerator$ClassLoaderData$3.apply(AbstractClassGenerator.java:108) ~[spring-core-5.1.4.RELEASE.jar:?]
at org.springframework.cglib.core.internal.LoadingCache$2.call(LoadingCache.java:54) ~[spring-core-5.1.4.RELEASE.jar:?]
at java.util.concurrent.FutureTask.run$$$capture(FutureTask.java:264) ~[?:?]
at java.util.concurrent.FutureTask.run(FutureTask.java) ~[?:?]
at org.springframework.cglib.core.internal.LoadingCache.createEntry(LoadingCache.java:61) ~[spring-core-5.1.4.RELEASE.jar:?]
at org.springframework.cglib.core.internal.LoadingCache.get(LoadingCache.java:34) ~[spring-core-5.1.4.RELEASE.jar:?]
at org.springframework.cglib.core.AbstractClassGenerator$ClassLoaderData.get(AbstractClassGenerator.java:134) ~[spring-core-5.1.4.RELEASE.jar:?]
at org.springframework.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:319) ~[spring-core-5.1.4.RELEASE.jar:?]
at org.springframework.cglib.proxy.Enhancer.createHelper(Enhancer.java:569) ~[spring-core-5.1.4.RELEASE.jar:?]
at org.springframework.cglib.proxy.Enhancer.createClass(Enhancer.java:416) ~[spring-core-5.1.4.RELEASE.jar:?]
at org.springframework.context.annotation.ConfigurationClassEnhancer.createClass(ConfigurationClassEnhancer.java:137) ~[spring-context-5.1.4.RELEASE.jar:?]
at org.springframework.context.annotation.ConfigurationClassEnhancer.enhance(ConfigurationClassEnhancer.java:109) ~[spring-context-5.1.4.RELEASE.jar:?]
at org.springframework.context.annotation.ConfigurationClassPostProcessor.enhanceConfigurationClasses(ConfigurationClassPostProcessor.java:402) ~[spring-context-5.1.4.RELEASE.jar:?]
... 14 more
Caused by: java.lang.IllegalAccessException: module spring.core does not read module myapplication.module1
at java.lang.invoke.MethodHandles.privateLookupIn(MethodHandles.java:197) ~[?:?]
at jdk.internal.reflect.GeneratedMethodAccessor22.invoke(Unknown Source) ~[?:?]
at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?]
at java.lang.reflect.Method.invoke(Method.java:566) ~[?:?]
at org.springframework.cglib.core.ReflectUtils.defineClass(ReflectUtils.java:497) ~[spring-core-5.1.4.RELEASE.jar:?]
at org.springframework.cglib.core.AbstractClassGenerator.generate(AbstractClassGenerator.java:363) ~[spring-core-5.1.4.RELEASE.jar:?]
at org.springframework.cglib.proxy.Enhancer.generate(Enhancer.java:582) ~[spring-core-5.1.4.RELEASE.jar:?]
at org.springframework.cglib.core.AbstractClassGenerator$ClassLoaderData$3.apply(AbstractClassGenerator.java:110) ~[spring-core-5.1.4.RELEASE.jar:?]
at org.springframework.cglib.core.AbstractClassGenerator$ClassLoaderData$3.apply(AbstractClassGenerator.java:108) ~[spring-core-5.1.4.RELEASE.jar:?]
at org.springframework.cglib.core.internal.LoadingCache$2.call(LoadingCache.java:54) ~[spring-core-5.1.4.RELEASE.jar:?]
at java.util.concurrent.FutureTask.run$$$capture(FutureTask.java:264) ~[?:?]
at java.util.concurrent.FutureTask.run(FutureTask.java) ~[?:?]
at org.springframework.cglib.core.internal.LoadingCache.createEntry(LoadingCache.java:61) ~[spring-core-5.1.4.RELEASE.jar:?]
at org.springframework.cglib.core.internal.LoadingCache.get(LoadingCache.java:34) ~[spring-core-5.1.4.RELEASE.jar:?]
at org.springframework.cglib.core.AbstractClassGenerator$ClassLoaderData.get(AbstractClassGenerator.java:134) ~[spring-core-5.1.4.RELEASE.jar:?]
at org.springframework.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:319) ~[spring-core-5.1.4.RELEASE.jar:?]
at org.springframework.cglib.proxy.Enhancer.createHelper(Enhancer.java:569) ~[spring-core-5.1.4.RELEASE.jar:?]
at org.springframework.cglib.proxy.Enhancer.createClass(Enhancer.java:416) ~[spring-core-5.1.4.RELEASE.jar:?]
at org.springframework.context.annotation.ConfigurationClassEnhancer.createClass(ConfigurationClassEnhancer.java:137) ~[spring-context-5.1.4.RELEASE.jar:?]
at org.springframework.context.annotation.ConfigurationClassEnhancer.enhance(ConfigurationClassEnhancer.java:109) ~[spring-context-5.1.4.RELEASE.jar:?]
at org.springframework.context.annotation.ConfigurationClassPostProcessor.enhanceConfigurationClasses(ConfigurationClassPostProcessor.java:402) ~[spring-context-5.1.4.RELEASE.jar:?]
... 14 more
问题:是否可以向Spring(实际上是spring.core
自动模块)授予驻留在子模块层中的类的访问权限?