【问题标题】:Illegal reflective access by org.springframework.cglib.core.ReflectUtils$1org.springframework.cglib.core.ReflectUtils 的非法反射访问 $1
【发布时间】:2018-03-22 03:21:55
【问题描述】:

我的 JDK 9+181 Spring Boot 2.0.0.BUILD-SNAPSHOT CLI 应用程序在启动时显示此警告:

WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.springframework.cglib.core.ReflectUtils$1 (jar:file:/home/jan/src/fm-cli/target/fm-cli-0.1.0-SNAPSHOT.jar!/BOOT-INF/lib/spring-core-5.0.0.RELEASE.jar!/) to method java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int,java.security.ProtectionDomain)
WARNING: Please consider reporting this to the maintainers of org.springframework.cglib.core.ReflectUtils$1

这是一个控制台应用程序,所以我需要禁用此警告 -- 我该怎么做?

注意:这个问题问的是如何禁用Spring触发的这个警告的具体问题;它不是 JDK9: An illegal reflective access operation has occurred. org.python.core.PySystemState 的副本,后者在不同的库中处理类似的症状。

【问题讨论】:

    标签: java spring spring-boot java-9 java-module


    【解决方案1】:

    在 JDK 9+ 中,将以下选项添加到 JVM 以禁用 Spring 使用 CGLIB 的警告:

    --add-opens java.base/java.lang=ALL-UNNAMED
    

    例如:

    java --add-opens java.base/java.lang=ALL-UNNAMED -jar target/*.jar
    

    无需报告;这是known Spring bug

    发生这种情况是因为新的 JDK 9 模块系统检测到非法访问,该访问将在(不久的)将来的某个时候被禁止。你可以阅读更多关于the JDK 9 Module system here的信息。

    更新

    JDK 9+ 和 Spring 5.1+ 可修复此问题。

    【讨论】:

    • 我正在使用带有 JDK 9.0.4 的 Spring Boot 2.0.0.RC1,并且面临同样的问题。你能解释一下这个技巧吗? switch是什么意思?
    • @DoNhuVy -- 考虑提出一个关于如何做到这一点的新问题。您可以在这里找到更多信息:intellij-support.jetbrains.com/hc/en-us/articles/…
    • 我在这里添加问题:stackoverflow.com/questions/48811990/…
    • 似乎该问题也出现在 JDK 10 中-您能解释一下如何将--add-opens java.base/java.lang=ALL-UNNAMED 添加到 JVM 中吗?我不熟悉如何编辑它。
    • 该问题已得到解决,该修复将成为 Spring 5.1 的一部分。
    【解决方案2】:

    这也发生在我的 JDK 11 和 Spring Boot 2.2.1 (Spring Core 5.2.1) 上。

    按照some commentsSpring Framework issue #22814 中的建议,删除对org.springframework.boot:spring-boot-devtools 的依赖项有所帮助。

    【讨论】:

      【解决方案3】:

      添加到上面的 Jan Nielsen 答案,如果您使用 Intellij 和 Spring Boot 2.0.3,它依赖于 Spring 核心 5.0.7,您仍然被卡住并且没有修复。

      我的出路需要两件事:

      • 将 Jan 提到的 --add-opens 添加到您的运行/调试配置中。只需编辑配置并在 Environment / VM Options 下查看。这负责消除一些“非法访问消息”。

      • 我还需要向 jaxb-api 库添加一个依赖项。我从 ValentinBossi 对this spring github issue 的评论中得到了暗示。

      【讨论】:

        【解决方案4】:

        使用 spring 初始化器时,请确保使用最新版本的 Spring Boot。它会自动为您获取 Spring core 5.1 或更高版本,并且您在运行项目时不会看到错误。

        因此您不必担心编辑任何 JVM 配置。

        【讨论】:

        • 我在 5.3.3 上得到这个。 Spring Boot 2.4.2版
        【解决方案5】:

        在这些警告之后,如果您的应用仍然无法运行,则将此依赖项添加到您的 pom.xml

        <dependency>
            <groupId>javax.xml.bind</groupId>
            <artifactId>jaxb-api</artifactId>
            <version>2.3.0</version>
        </dependency>
        

        这对我有帮助!

        【讨论】:

          【解决方案6】:

          我坐在这些版本上,但我仍然看到警告:

          • SpringBoot 2.4.1
          • Spring Core FW:5.3.2(我的父pom是Spring Boot的,所以这个版本是它引入的,不是我手动设置的)
          • Java openjdk 版本“11.0.9.1”2020-11-04

          从 spring-boot-devtools 中删除依赖项也对我有用,启动时警告不再存在。

          <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <optional>true</optional>
          </dependency>
          

          ... 归根结底,我只是在类路径发生任何更改时从我的 IDE 中使用自动重新启动,而我可以不用它就离开。 不过,问题是理论上我们不应该担心它,因为根据Spring documentation

          运行完全打包的应用程序时,开发人员工具会自动禁用。如果您的应用程序是使用 java -jar 启动的,或者它是使用特殊的类加载器启动的,那么它被视为“生产应用程序”

          因此可以预期,当应用程序从命令行启动时,警告应该会消失(我尚未验证)。

          【讨论】:

            【解决方案7】:

            如果你使用maven和spring,请升级到Spring Framework 5.1+ / Spring Boot 2.1+。

            【讨论】:

              猜你喜欢
              • 1970-01-01
              • 2019-04-17
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 2018-10-19
              • 1970-01-01
              • 1970-01-01
              相关资源
              最近更新 更多