问题
I'm trying Java 10 development with Spring Boot 2 and I encounter some issues.
The application is a simple webapp based upon Spring Boot 2. The application launch is ok but when I stop it, I get this warning:
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
As you see, I already switch the embeded Tomcat server from version 8 to 9.0.11 to be compliant with the Java module system. And the application is launched with the option --add-opens java.base/java.lang=ALL-UNNAMED
Does anybody know why I get this message ?
回答1:
To silence these warnings, you will need the following options in your startup script:
--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
as you can see in the Tomcat 9 startup script.
The fixes for the warnings are not likely to be addressed anytime soon:
Are there plans to address these in a future release?
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.
来源:https://stackoverflow.com/questions/52185626/illegal-reflective-access-when-i-stop-springboot-web-application-with-tomcat-9-a