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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/46671472/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-12 02:26:48  来源:igfitidea点击:

Illegal reflective access by org.springframework.cglib.core.ReflectUtils$1

javaspringspring-bootjava-9java-module

提问by Jan Nielsen

My JDK 9+181 Spring Boot 2.0.0.BUILD-SNAPSHOT CLI application displays this warning on startup:

我的 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 (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

This is a console application, so I need to disable this warning -- how can I do that?

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

Note:This question asks the specific question of how to disable this warning triggered by Spring; it is not a duplicate of JDK9: An illegal reflective access operation has occurred. org.python.core.PySystemStatewhich deals with a similar symptom in a different library.

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

采纳答案by Jan Nielsen

In JDK 9+, add the following option to the JVM to disable the warning from Spring's use of CGLIB:

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

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

for example:

例如:

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

No need to report it; it's a known Spring bug.

无需报告;这是一个已知的 Spring 错误

This happens because the new JDK 9 module system detected an illegal access that will be disallowed sometime in the (near) future. You can read more about the JDK 9 Module system here.

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

Update:

更新

A fix for this issue is available JDK 9+ with Spring 5.1+.

JDK 9+ 和 Spring 5.1+ 提供了此问题的修复程序。

回答by Coffee_fan

Adding to Jan Nielsen answer above, if you are using Intellij and Spring Boot 2.0.3, which depends on Spring core 5.0.7, you are still stuck and do not have the fix.

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

The way out for me needed two things:

我的出路需要两件事:

  • Add the --add-opensmentioned by Jan to your run/debug configuration. Just edit the configuration and look under Environment / VM Options. This takes care of silencing some of the "illegal access messages".

  • I also needed to add a dependency to the jaxb-apilibrary. I got the hint from ValentinBossi comment on this spring github issue.

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

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

回答by Onome Sotu

When using the spring initializer, make sure you use the latest version of Spring Boot. It automatically gets Spring core 5.1 or greater for you and you won't see the error when you run the project.

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

So you don't have to worry about editing any JVM configuration.

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

回答by kalariya parikshith

After these warnings, if your app is still not working then add this dependency to your pom.xml

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

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

This helped me!!

这对我有帮助!!

回答by msd.salehi

Getting the same warning running on:

继续运行相同的警告:

  • openJDK 11.0.2
  • spring-core/5.1.12.RELEASE
  • openJDK 11.0.2
  • spring-core/5.1.12.RELEASE

Warning message:

警告信息:

WARNING: Illegal reflective access by org.springframework.cglib.core.ReflectUtils (file:/***/.m2/repository/org/springframework/spring-core/5.1.12.RELEASE/spring-core-5.1.12.RELEASE.jar) to method java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int,java.security.ProtectionDomain)

回答by Cos64

This also happened to me on JDK 11 and Spring Boot 2.2.1 (Spring Core 5.2.1).

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

What helped was removing the dependency to org.springframework.boot:spring-boot-devtools, as suggested in somecommentsto Spring Framework issue #22814.

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