【问题标题】:Spring Boot and ENUMs cause An illegal reflective access operationSpring Boot 和 ENUMs 导致非法反射访问操作
【发布时间】:2020-06-15 07:52:41
【问题描述】:

我使用的是 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 或 RelationshipEnity。事实上,这个枚举只是在类路径中。它没有在任何地方使用。

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

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

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

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

【问题讨论】:

    标签: java spring spring-boot exception enums


    【解决方案1】:
    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 框架提交问题(或检查是否已经存在)。

    【讨论】:

    【解决方案2】:

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

    这只是一个警告,但在向客户发送代码时我不能接受。

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

    【讨论】:

      猜你喜欢
      • 2021-08-29
      • 2019-09-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-02-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多