Springboot启动报警告jdk版本11

在这里插入图片描述
警告如下:

WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.springframework.cglib.core.ReflectUtils$1 (file:/C:/Users/Administrator/.m2/repository/org/springframework/spring-core/4.3.6.RELEASE/spring-core-4.3.6.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$1
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

解决办法:
在启动类增加以下方法,亲测试 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){

        }
    }

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

@SpringBootApplication
public class APP {

    public static void main(String[] args) {

         disableWarning(); //禁用警告
        SpringApplication.run(APP.class,args);
    }

猜你喜欢

转载自blog.csdn.net/qq_39162487/article/details/110261822
今日推荐