org.springframework.cglib.core.ReflectUtils $ 1的非法反射访问

Jan*_*sen 40 java spring spring-boot java-9 java-module

我的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
Run Code Online (Sandbox Code Playgroud)

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

注意:此问题询问如何禁用Spring触发此警告的具体问题; 它不是JDK9的副本:发生了非法的反射访问操作.org.python.core.PySystemState,用于处理不同库中的类似症状.

Jan*_*sen 54

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

--add-opens java.base/java.lang=ALL-UNNAMED
Run Code Online (Sandbox Code Playgroud)

例如:

java --add-opens java.base/java.lang=ALL-UNNAMED -jar target/*.jar
Run Code Online (Sandbox Code Playgroud)

无需报告; 这是一个已知的Spring bug.

发生这种情况是因为新的JDK 9模块系统检测到非法访问,该访问将在(近)未来的某个时间被禁止.您可以在此处阅读有关JDK 9模块系统的更多信息.

更新:

有关此问题的修复程序可用于Spring 5.1+的JDK 9+.

  • @DoNhuVy——考虑提出一个关于如何做到这一点的新问题。您可以在此处找到更多信息:https://intellij-support.jetbrains.com/hc/en-us/articles/206544869-Configuring-JVM-options-and-platform-properties (2认同)
  • 似乎这个问题也出现在 JDK 10 中 - 你能解释一下我如何将 `--add-opens java.base/java.lang=ALL-UNNAMED` 添加到 JVM 中吗?我不熟悉如何编辑它。 (2认同)

Cos*_*s64 12

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

org.springframework.boot:spring-boot-devtools正如对Spring Framework 问题 #22814 的一些 评论所建议的那样,有助于消除对 的依赖。


Cof*_*fan 6

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

我的出路需要两件事:

  • Jan 提到的--add-opens添加到您的运行/调试配置中。只需编辑配置并查看环境/VM 选项。这负责使某些“非法访问消息”静音。

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