弹簧启动和枚举导致非法的反射访问操作



我正在使用Spring Boot,NEO4J作为数据库。我正在使用Java 13和Spring 2.3.1。我的代码中有一个枚举:

package uk.co.osiris.entities;
public enum Involvement {
Master,
Charterer, 
Owner,
DesponentOwner,
Agent, 
Inspector,
PortAuthority, 
Other
}

它不用于 NodeEntity 或 RelationsEnity。实际上,这个枚举只是在类路径中。它没有在任何地方使用。

当我运行应用程序时,我得到:

WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.springframework.util.ReflectionUtils (file:/home/adrian/.m2/repository/org/springframework/spring-core/5.2.7.RELEASE/spring-core-5.2.7.RELEASE.jar) to field java.lang.Enum.name
WARNING: Please consider reporting this to the maintainers of org.springframework.util.ReflectionUtils
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

我可以,而且对他们来说可能会,只是删除枚举。

但是为什么我会得到这个?

WARNING: Illegal reflective access by org.springframework.util.ReflectionUtils (file:/home/adrian/.m2/repository/org/springframework/spring-core/5.2.7.RELEASE/spring-core-5.2.7.RELEASE.jar) to field java.lang.Enum.name
WARNING: Please consider reporting this to the maintainers of org.springframework.util.ReflectionUtils
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

据我所知,这(只是(在使用Java 11+时Spring中出现问题的警告。不过,现在一切应该仍然运行良好,AFAIK。

然而,Spring应该解决这个问题,以确保一旦非法访问操作被拒绝,框架也适用于未来的Java版本。

考虑为 Spring 框架提交一个问题(或检查是否已经存在一个问题(。

我已经确认这是使用Java 9的Spring Framework的问题。它给出了Java 11和13的警告消息,包括OpenJDK和Oracle JDK。这似乎发生在您使用Java JPA时。我碰巧正在使用Neo4J,但我怀疑其他数据库可能会遇到同样的问题。

这只是一个警告,但我在将代码交付给客户端时不能接受。

所以,我降级到 Java 1.8 :-{

最新更新