您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

Spring Boot 警告:An illegal reflective access operation has occurred

bubuko 2022/1/25 19:13:35 java 字数 6513 阅读 861 来源 http://www.bubuko.com/infolist-5-1.html

Spring Boot 警告:An illegal reflective access operation has occurred 博主:?ifu25 问题描述 最新将Spring Boot项目升级到JDK 11,运行时发现警告如下: WARNING: An illegal reflective ...

Spring Boot 警告:An illegal reflective access operation has occurred

问题描述

最新将Spring Boot项目升级到JDK 11,运行时发现警告如下:

WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.springframework.cglib.core.ReflectUtils (file:/D:/Android/.gradle/caches/modules-2/files-2.1/org.springframework/spring-core/5.2.0.RELEASE/e0e1b3c304f70ed19d7905975f6f990916ada219/spring-core-5.2.0.RELEASE.jar) to method java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int,java.security.ProtectionDomain)
WARNING: Please consider reporting this to the maintainers of org.springframework.cglib.core.ReflectUtils
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

20191021205420.png

 

解决方案

 

方案一

增加 JVM 启动参数:

java --illegal-access=deny

 

Java 9 中这个参数默认是:permit

20191021205515.png

 

方案二

在启动类增加以下方法,亲测试 jdk 11 有效

public static void disableWarning() {
    try {
        Field theUnsafe = Unsafe.class.getDeclaredField("theUnsafe");
        theUnsafe.setAccessible(true);
        Unsafe u = (Unsafe) theUnsafe.get(null);

        Class cls = Class.forName("jdk.internal.module.IllegalAccessLogger");
        Field logger = cls.getDeclaredField("logger");
        u.putObjectVolatile(cls, u.staticFieldOffset(logger), null);
    } catch (Exception e) {
        // ignore
    }
}

 

启动 Spring Boot 时调用一下上面的方法

public static void main(String[] args) {
    disableWarning(); //禁用警告
    SpringApplication.run(AppApplication.class, args);
}

 

 

参考

参考:
https://stackoverflow.com/questions/46454995/how-to-hide-warning-illegal-reflective-access-in-java-9-without-jvm-argument
https://blog.csdn.net/qq_25958497/article/details/87258748
https://stackoverflow.com/questions/53790182/get-the-current-value-of-illegal-access-setting-in-java

 

处理“Error:(11, 25) java: 程序包jdk.internal.misc不存在” 的问题

方案一: 把jdk 切换为 1.8版本

 
 
 
 
 
 
 
 

Spring Boot 警告:An illegal reflective access operation has occurred

原文:https://www.cnblogs.com/ios9/p/14586354.html


如果您也喜欢它,动动您的小指点个赞吧

除非注明,文章均由 laddyq.com 整理发布,欢迎转载。

转载请注明:
链接:http://laddyq.com
来源:laddyq.com
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。


联系我
置顶