java - netty "Reflective setAccessible(true) disabled"的 spring-web-flux 错误

标签 java spring-boot spring-webflux reactor-netty

我有一个像上面一样的 junit 测试,但是当我启动测试时,我收到这个错误(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 文件:
    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:
    <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

到我的测试配置

enter image description here

关于java - netty "Reflective setAccessible(true) disabled"的 spring-web-flux 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59411821/

相关文章:

spring - 创建自动配置 spring 库到 spring-boot 应用程序

java - 如何访问通过 Twilio 发送到我的 Spring Boot Controller 的 SMS 文本?

spring - 在 bean 初始化期间使用响应式存储库 - 我需要 block() 吗?

spring-boot - 如何调试永远无法完成的 Mono

java - Java 15 的密封类功能中的最终类和非密封类有什么区别?

java - JSF 框架中的资源配置

java - Hibernate 将两个表映射到一个类

java - 在 spring 中创建动态操作并将变量传递给请求映射时出现错误

ssl - JHipster 运行但没有发生 SSL 挑战

java - SpringWebFlux doOnError 处理