带有 netty 的 spring-web-flux 错误“已禁用反射 setAccessible(true)" [英] spring-web-flux error with netty "Reflective setAccessible(true) disabled"

查看:23
本文介绍了带有 netty 的 spring-web-flux 错误“已禁用反射 setAccessible(true)"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个像上面一样的 junit 测试,但是当我启动测试时,我收到这个错误 (JDK 13.0.1):

I have a junit test like above but when i launch test, i get this error (JDK 13.0.1):

java.lang.UnsupportedOperationException: Reflective setAccessible(true) disabled
java.lang.IllegalAccessException: class io.netty.util.internal.PlatformDependent0$6 cannot access class jdk.internal.misc.Unsafe (in module java.base) because module java.base does not export jdk.internal.misc to unnamed module @4a94ee4

我的工具是 Intellij CE Edition 2019.3.1.这是我的类和 pom 文件:

My tool is Intellij CE Edition 2019.3.1. This is my class and pom file:

    import org.junit.jupiter.api.Assertions;
    import org.junit.jupiter.api.Test;
    import org.springframework.web.reactive.function.client.WebClient;
    import reactor.core.publisher.Flux;

    class WebClientStockClientIntegrationTest {

        private static final String SYMBOL = "EUR";
        private WebClient webClient = WebClient.builder().build();

        @Test
        void shouldRetrieveStockPricesFromStockService() {
            WebClientStockClient webClientStockClient = new WebClientStockClient(webClient);
            Flux<StockPrice> prices = webClientStockClient.pricesFor(SYMBOL);
            Assertions.assertNotNull(prices);
            Assertions.assertTrue(prices.take(5).count().block() > 0);
        }
}

我的带有 spring-boot 和依赖项的 pom:

My pom with spring-boot and dependencies:

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.2.2.RELEASE</version>
        ..

    <properties>
        <java.version>11</java.version>
    </properties>

推荐答案

我解决了:我补充:

--add-opens java.base/jdk.internal.misc=ALL-UNNAMED -Dio.netty.tryReflectionSetAccessible=true

到我的测试配置

这篇关于带有 netty 的 spring-web-flux 错误“已禁用反射 setAccessible(true)"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆