SpringBoot报警告WARNING: An illegal reflective access operation has occurred

错误详情

image.png
由于我将8的项目升级到了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
    }
}

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


版权声明:本文为qq_37350725原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。