14

我正在尝试使用 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

有人知道我为什么收到这条消息吗?

4

1 回答 1

10

要使这些警告静音,您需要在启动脚本中使用以下选项:

--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 启动脚本中看到的那样。

警告的修复不太可能很快得到解决

是否有计划在未来的版本中解决这些问题?

Not at the moment.

We'll keep the explicit clearing in place as long as we can. Once it is permanently blocked we'll probably have to rely on the fact that the Maps in question use a WeakReference and wait for GC to clear the references. That will make tracking down genuine memory leaks harder so we'll have to see if we can persuade the JRE team to provide some sort of replacement API if/when we reach that point.

于 2018-10-30T17:36:32.210 回答