我正在尝试使用 Spring Boot 2 进行 Java 10 开发,但遇到了一些问题。
该应用程序是一个基于 Spring Boot 2 的简单 Web 应用程序。应用程序启动正常,但当我停止它时,我收到此警告:
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.apache.catalina.loader.WebappClassLoaderBase (file:/C:/Users/CS/.m2/repository/org/apache/tomcat/embed/tomcat-embed-core/9.0.11/tomcat-embed-core-9.0.11.jar) to field java.io.ObjectStreamClass$Caches.localDescs
WARNING: Please consider reporting this to the maintainers of org.apache.catalina.loader.WebappClassLoaderBase
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
如您所见,我已经将嵌入式 Tomcat 服务器从版本 8 切换到 9.0.11 以与 Java 模块系统兼容。应用程序使用选项 --add-opens java.base/java.lang=ALL-UNNAMED
有人知道我为什么收到这条消息吗?
最佳答案
要消除这些警告,您需要在启动脚本中添加以下选项:
--add-opens=java.base/java.lang=ALL-UNNAMED
--add-opens=java.base/java.io=ALL-UNNAMED
--add-opens=java.rmi/sun.rmi.transport=ALL-UNNAMED
正如您在 Tomcat 9 startup script 中看到的那样.
警告的修复是 not likely to be addressed anytime soon :
Are there plans to address these in a future release?
暂时没有。
我们会尽可能长时间地保留明确的清理。一旦它 被永久封锁我们可能不得不依赖这样一个事实 有问题的 map 使用 WeakReference 并等待 GC 清除 引用。这将使追踪真正的内存泄漏变得更加困难 所以我们得看看能否说服 JRE 团队提供一些 如果/当我们达到那个点时,某种替换 API。
关于java - 当我停止使用 Tomcat 9 和 Java 10 的 Spring Boot Web 应用程序时的非法反射访问,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52185626/