具有Java 11引发的Spring Boot多模块项目无法访问类org.springframework.cglib.core.ReflectUtils

时间:2019-04-17 06:01:15

标签: spring-boot java-11

我正在创建Java 11 Spring Boot(2.1.3版)多模块项目,但是在运行子模块时遇到以下异常。当我将其作为单个项目(没有多模块)运行时,一切工作正常。

java.lang.IllegalStateException: Cannot load configuration class: f

etch.App
    at spring.context@5.1.5.RELEASE/org.springframework.context.annotation.ConfigurationClassPostProcessor.enhanceConfigurationClasses(ConfigurationClassPostProcessor.java:413) ~[spring-context-5.1.5.RELEASE.jar:na]
    at spring.context@5.1.5.RELEASE/org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanFactory(ConfigurationClassPostProcessor.java:253) ~[spring-context-5.1.5.RELEASE.jar:na]
    at spring.context@5.1.5.RELEASE/org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:286) ~[spring-context-5.1.5.RELEASE.jar:na]
    at spring.context@5.1.5.RELEASE/org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:130) ~[spring-context-5.1.5.RELEASE.jar:na]
    at spring.context@5.1.5.RELEASE/org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:705) ~[spring-context-5.1.5.RELEASE.jar:na]
    at spring.context@5.1.5.RELEASE/org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:531) ~[spring-context-5.1.5.RELEASE.jar:na]
    at spring.boot@2.1.3.RELEASE/org.springframework.boot.SpringApplication.refresh(SpringApplication.java:775) ~[spring-boot-2.1.3.RELEASE.jar:na]
    at spring.boot@2.1.3.RELEASE/org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) ~[spring-boot-2.1.3.RELEASE.jar:na]
    at spring.boot@2.1.3.RELEASE/org.springframework.boot.SpringApplication.run(SpringApplication.java:316) ~[spring-boot-2.1.3.RELEASE.jar:na]
    at spring.boot@2.1.3.RELEASE/org.springframework.boot.SpringApplication.run(SpringApplication.java:1260) ~[spring-boot-2.1.3.RELEASE.jar:na]
    at spring.boot@2.1.3.RELEASE/org.springframework.boot.SpringApplication.run(SpringApplication.java:1248) ~[spring-boot-2.1.3.RELEASE.jar:na]
    at legalAppFetchModule/fetch.App.main(App.java:16) ~[classes/:na]
Caused by: java.lang.IllegalStateException: Unable to load cache item
    at org.springframework.cglib.core.internal.LoadingCache.createEntry(LoadingCache.java:79) ~[spring-core-5.1.5.RELEASE.jar:5.1.5.RELEASE]
    at org.springframework.cglib.core.internal.LoadingCache.get(LoadingCache.java:34) ~[spring-core-5.1.5.RELEASE.jar:5.1.5.RELEASE]
    at org.springframework.cglib.core.AbstractClassGenerator$ClassLoaderData.get(AbstractClassGenerator.java:134) ~[spring-core-5.1.5.RELEASE.jar:5.1.5.RELEASE]
    at org.springframework.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:319) ~[spring-core-5.1.5.RELEASE.jar:5.1.5.RELEASE]
    at org.springframework.cglib.proxy.Enhancer.createHelper(Enhancer.java:569) ~[spring-core-5.1.5.RELEASE.jar:5.1.5.RELEASE]
    at org.springframework.cglib.proxy.Enhancer.createClass(Enhancer.java:416) ~[spring-core-5.1.5.RELEASE.jar:5.1.5.RELEASE]
    at spring.context@5.1.5.RELEASE/org.springframework.context.annotation.ConfigurationClassEnhancer.createClass(ConfigurationClassEnhancer.java:137) ~[spring-context-5.1.5.RELEASE.jar:na]
    at spring.context@5.1.5.RELEASE/org.springframework.context.annotation.ConfigurationClassEnhancer.enhance(ConfigurationClassEnhancer.java:109) ~[spring-context-5.1.5.RELEASE.jar:na]
    at spring.context@5.1.5.RELEASE/org.springframework.context.annotation.ConfigurationClassPostProcessor.enhanceConfigurationClasses(ConfigurationClassPostProcessor.java:402) ~[spring-context-5.1.5.RELEASE.jar:na]
    ... 11 common frames omitted
Caused by: java.lang.IllegalAccessError: class fetch.App$$EnhancerBySpringCGLIB$$4423c935 (in module legalAppFetchModule) cannot access class org.springframework.cglib.core.ReflectUtils (in unnamed module @0x50378a4) because module legalAppFetchModule does not read unnamed module @0x50378a4
    at legalAppFetchModule/fetch.App$$EnhancerBySpringCGLIB$$4423c935.CGLIB$STATICHOOK1(<generated>) ~[classes/:na]
    at legalAppFetchModule/fetch.App$$EnhancerBySpringCGLIB$$4423c935.<clinit>(<generated>) ~[classes/:na]
    at java.base/java.lang.Class.forName0(Native Method) ~[na:na]
    at java.base/java.lang.Class.forName(Class.java:398) ~[na:na]
    at org.springframework.cglib.core.ReflectUtils.defineClass(ReflectUtils.java:537) ~[spring-core-5.1.5.RELEASE.jar:5.1.5.RELEASE]
    at org.springframework.cglib.core.AbstractClassGenerator.generate(AbstractClassGenerator.java:363) ~[spring-core-5.1.5.RELEASE.jar:5.1.5.RELEASE]
    at org.springframework.cglib.proxy.Enhancer.generate(Enhancer.java:582) ~[spring-core-5.1.5.RELEASE.jar:5.1.5.RELEASE]
    at org.springframework.cglib.core.AbstractClassGenerator$ClassLoaderData$3.apply(AbstractClassGenerator.java:110) ~[spring-core-5.1.5.RELEASE.jar:5.1.5.RELEASE]
    at org.springframework.cglib.core.AbstractClassGenerator$ClassLoaderData$3.apply(AbstractClassGenerator.java:108) ~[spring-core-5.1.5.RELEASE.jar:5.1.5.RELEASE]
    at org.springframework.cglib.core.internal.LoadingCache$2.call(LoadingCache.java:54) ~[spring-core-5.1.5.RELEASE.jar:5.1.5.RELEASE]
    at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264) ~[na:na]
    at org.springframework.cglib.core.internal.LoadingCache.createEntry(LoadingCache.java:61) ~[spring-core-5.1.5.RELEASE.jar:5.1.5.RELEASE]
    ... 19 common frames omitted

请参阅父pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <!--  lookup parent from repository --> 
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.3.RELEASE</version>
        <relativePath/> 
    </parent>

    <groupId>com.example</groupId>
    <artifactId>demoMultiModule</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>demoMultiModule</name>
    <description>Demo project for Spring Boot</description>
    <packaging>pom</packaging>
    <properties>
        <java.version>11</java.version>
    </properties>


    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>


    <modules>
        <module>fetch</module>
    </modules>
</project>

请参阅子pom.xml

<?xml version="1.0"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <modelVersion>4.0.0</modelVersion>
  <parent>
    <groupId>com.example</groupId>
    <artifactId>demoMultiModule</artifactId>
    <version>0.0.1-SNAPSHOT</version>
  </parent>
    <artifactId>fetch</artifactId>

  <name>fetch</name>
  <url>http://maven.apache.org</url>
  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>
  <dependencies>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
  </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
</project>

我可以看到一个相关的春季问题(https://github.com/spring-projects/spring-framework/issues/20414),还有一个问题(Illegal reflective access by org.springframework.cglib.core.ReflectUtils$1)。根据他们的说法,它必须在spring5.1 +中已修复,而我正在使用Spring-web.5.1.5。因此,它应该没有任何问题。

为完整起见,请参见我的模块路径和子模块的module-info.java文件 enter image description here

module-info.java

open module legalAppFetchModule {
    requires spring.boot.autoconfigure;
    requires spring.boot;
    requires spring.web;
}

有人可以请点灯吗

2 个答案:

答案 0 :(得分:0)

在模块路径中添加了spring-core和spring-beans之后,它不再抱怨服务器仍未完全运行,但是我认为这可能是由于其他原因所致。但是就发布的问题而言,问题已经解决

enter image description here

答案 1 :(得分:0)

将spring.core和spring.beans添加到模块依赖项(已经完成)。

另外,将其添加到应用程序运行配置的arguments选项卡的VM参数中:

--add-modules=ALL-SYSTEM

您还可以在 Window> Preferences> Java> Installed JREs 下将此设置为默认选项。 选择您的JRE / JDK并进行编辑。在默认VM参数

下添加以上选项