当前位置: 首页 > 知识库问答 >
问题:

带有Java11抛出的SpringBoot多模块项目无法访问类org。springframework。cglib。果心反思

孔星宇
2023-03-14

我正在创建一个Java11SpringBoot(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>

我可以看到一个相关的Spring问题(https://github.com/spring-projects/spring-framework/issues/20414),所以问题(org.springframework.cglib.core.ReflectUtils1美元的非法反射访问)。根据他们的说法,它必须在spring5.1中修复,我正在使用Spring-web.5.1.5。因此,它不应该有任何问题。

module-info.java

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

谁能给我点光吗

共有2个答案

梁学真
2023-03-14

在将SpringCore和SpringBean添加到模块路径之后,它不再抱怨服务器仍然没有完全运行,但我认为这可能是由于其他原因,我必须进一步研究。但就发布的问题而言,它已经解决了

干旺
2023-03-14

添加Spring。芯和Spring。将bean添加到您的模块依赖项(您已经这样做了)。

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

--add-modules=ALL-SYSTEM

您还可以将其设置为“窗口”下的默认选项

 类似资料:
  • 我有一个带有myapp-core和myapp-web模块的myapp父pom类型maven项目。myapp-core模块作为依赖项添加到MyApp-Web。 myapp-core模块中的所有类都位于根包com.myapp.core中,而myapp-web模块中的所有类都位于根包com.myapp.web中 主要的application.java也在com.myapp.web包中。由于我的核心模块根

  • 我有一个基本的SpringBoot应用程序。使用Spring初始值设定项、嵌入式Tomcat、Thymeleaf模板引擎,并将包作为可执行的JAR文件。是一个带有Spring Boot的多模块项目,该项目将有3个模块。这里是父模块pom。xml 这里是模块核心 这里是模块web: 从父根目录,我使用以下方法生成所有模块: 但问题是tdk-web-0.0.2-SNAPSHOT。jar不包含tdk-c

  • 父项目为demo-mybatis子模块为mybatis-dao、demo-service。demo-mybatis pom.xml如下: 4.0.0 pom mybatis-DAO Demo-service Demo-mybatis-app org.springframework.Boot spring-boot-starter-parent 2.3.2.release com.example D

  • 我在eclipse中初始化了一个SpringBoot Rest,并使其成为一个动态Web项目。遵循了三轮胎原则,并在控制器类中声明了endpointURL。项目部署良好,但一旦我尝试访问返回404错误的endpoint。请参阅下面的示例。二手编译器-Maven和服务器-apache tomcat 9.0 主类.java } 示例控制器类

  • 我试图在Mac OS上运行一个示例JavaFX应用程序。 Build.Gradle Java类 怎么啦?由于某种原因,JavaFX库没有正确加载。可能是MacOS或openjfx的错误吗?