java.lang.NoClassDefFoundError : io/netty/util/concurrent/RejectedExecutionHandlers

标签 java consumer

我正在使用 pack jvm Consumer 编写测试,并且在运行测试时收到以下错误:-

代码:-

@Test
public void createUser() throws Exception {
    Map<String, String> responseHeaders = new HashMap<>();
    responseHeaders.put("Content-Type", "application/json;charset=UTF-8");
    PactFragment fragment = buildPublisherRequest(responseHeaders);

    MockProviderConfig config = MockProviderConfig.createDefault();


    MappingJackson2HttpMessageConverter converter = getMappingConverter();

    RestTemplate template = new RestTemplate(Collections.<HttpMessageConverter<?>> singletonList(converter));
    VerificationResult result = fragment.runConsumer(config, config1 -> {
        ConfigApplication ds = new ConfigApplication();
        RestApiServiceImpl rs = new RestApiServiceImpl();


        ReflectionTestUtils.setField(ds, "host", config.url());

        ReflectionTestUtils.setField(ds, "restApiService", template);


    });
    if (result instanceof PactError) {
        throw new RuntimeException(((PactError)result).error());
    }
    assertEquals(ConsumerPactTest.PACT_VERIFIED, result);
}

上面代码中fragment.runConsumer(...)这行发生了错误。

错误:-

java.lang.NoClassDefFoundError: io/netty/util/concurrent/RejectedExecutionHandlers
    at io.netty.channel.nio.NioEventLoopGroup.<init>(NioEventLoopGroup.java:70)
    at io.netty.channel.nio.NioEventLoopGroup.<init>(NioEventLoopGroup.java:65)
    at io.netty.channel.nio.NioEventLoopGroup.<init>(NioEventLoopGroup.java:56)
    at io.netty.channel.nio.NioEventLoopGroup.<init>(NioEventLoopGroup.java:48)
    at io.netty.channel.nio.NioEventLoopGroup.<init>(NioEventLoopGroup.java:40)
    at unfiltered.netty.Engine$Default$.workers(Engine.scala:22)
    at unfiltered.netty.Engine$Default$.workers(Engine.scala:20)
    at unfiltered.netty.Server.unfiltered$netty$Server$$workerGrp$lzycompute(Server.scala:43)
    at unfiltered.netty.Server.unfiltered$netty$Server$$workerGrp(Server.scala:43)
    at unfiltered.netty.Server.destroy(Server.scala:97)
    at unfiltered.netty.Server.stop(Server.scala:91)
    at au.com.dius.pact.consumer.UnfilteredMockProvider.stop(UnfilteredMockProvider.scala:35)
    at au.com.dius.pact.consumer.StatefulMockProvider$$anonfun$runAndClose$1.apply(MockProvider.scala:64)
    at au.com.dius.pact.consumer.StatefulMockProvider$$anonfun$runAndClose$1.apply(MockProvider.scala:58)
    at scala.util.Try$.apply(Try.scala:192)
    at au.com.dius.pact.consumer.StatefulMockProvider.runAndClose(MockProvider.scala:57)
    at au.com.dius.pact.consumer.ConsumerPactRunner.runAndWritePact(ConsumerPactRunner.scala:31)
    at au.com.dius.pact.model.PactFragment.duringConsumerSpec(PactFragment.scala:13)
    at au.com.dius.pact.model.PactFragment.runConsumer(PactFragment.scala:21)

现有依赖项:-

<dependency>
    <groupId>au.com.dius</groupId>
    <artifactId>pact-jvm-consumer-junit_2.11</artifactId>
    <version>3.3.3</version>
    <scope>test</scope>
</dependency>

我是否需要添加任何其他依赖项?

如何解决这个问题?

最佳答案

netty版本有问题。

不同版本的 spring-cloud-starter-eureka 和 pact-jvm-consumer_2.11 依赖中均使用了 netty。我已在 pact-jvm-consumer_2.11 中排除了 netty-handler,并且错误现已解决。

org.springframework.cloud:spring-cloud-starter-eureka

    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-eureka</artifactId>
    </dependency>

+- org.springframework.cloud:spring-cloud-starter-eureka:jar:1.1.0.RELEASE:compile
[INFO] |  +- org.springframework.cloud:spring-cloud-starter:jar:1.1.0.RELEASE:compile
[INFO] |  |  +- org.springframework.cloud:spring-cloud-context:jar:1.1.0.RELEASE:compile
[INFO] |  |  |  \- org.springframework.security:spring-security-crypto:jar:4.1.3.RELEASE:compile
[INFO] |  |  +- org.springframework.cloud:spring-cloud-commons:jar:1.1.0.RELEASE:compile
[INFO] |  |  \- org.springframework.security:spring-security-rsa:jar:1.0.1.RELEASE:compile
[INFO] |  |     \- org.bouncycastle:bcpkix-jdk15on:jar:1.47:compile
[INFO] |  |        \- org.bouncycastle:bcprov-jdk15on:jar:1.47:compile
[INFO] |  +- org.springframework.cloud:spring-cloud-netflix-core:jar:1.1.0.RELEASE:compile
[INFO] |  +- org.springframework.cloud:spring-cloud-netflix-eureka-client:jar:1.1.0.RELEASE:compile
[INFO] |  +- com.netflix.eureka:eureka-client:jar:1.4.6:compile
[INFO] |  |  +- org.codehaus.jettison:jettison:jar:1.3.7:runtime
[INFO] |  |  |  \- stax:stax-api:jar:1.0.1:runtime
[INFO] |  |  +- com.netflix.netflix-commons:netflix-eventbus:jar:0.3.0:runtime
[INFO] |  |  +- com.netflix.archaius:archaius-core:jar:0.7.4:compile
[INFO] |  |  +- javax.ws.rs:jsr311-api:jar:1.1.1:runtime
[INFO] |  |  +- com.netflix.servo:servo-core:jar:0.10.1:runtime
[INFO] |  |  |  \- com.netflix.servo:servo-internal:jar:0.10.1:runtime
[INFO] |  |  +- com.sun.jersey:jersey-core:jar:1.19.1:runtime
[INFO] |  |  +- com.sun.jersey:jersey-client:jar:1.19.1:runtime
[INFO] |  |  +- com.sun.jersey.contribs:jersey-apache-client4:jar:1.19.1:runtime
[INFO] |  |  +- org.apache.httpcomponents:httpclient:jar:4.5.2:compile
[INFO] |  |  |  +- org.apache.httpcomponents:httpcore:jar:4.4.5:compile
[INFO] |  |  |  \- commons-codec:commons-codec:jar:1.10:compile
[INFO] |  |  +- com.google.inject:guice:jar:4.0:runtime
[INFO] |  |  |  +- javax.inject:javax.inject:jar:1:runtime
[INFO] |  |  |  \- aopalliance:aopalliance:jar:1.0:runtime
[INFO] |  |  \- com.netflix.governator:governator-api:jar:1.12.10:runtime
[INFO] |  +- com.netflix.eureka:eureka-core:jar:1.4.6:compile
[INFO] |  |  +- com.amazonaws:aws-java-sdk-core:jar:1.10.30:runtime
[INFO] |  |  +- com.amazonaws:aws-java-sdk-ec2:jar:1.10.30:runtime
[INFO] |  |  +- com.amazonaws:aws-java-sdk-autoscaling:jar:1.9.3:runtime
[INFO] |  |  +- com.amazonaws:aws-java-sdk-sts:jar:1.9.3:runtime
[INFO] |  |  +- com.amazonaws:aws-java-sdk-route53:jar:1.9.3:runtime
[INFO] |  |  +- com.netflix.governator:governator:jar:1.12.10:runtime
[INFO] |  |  |  +- com.netflix.governator:governator-core:jar:1.12.10:runtime
[INFO] |  |  |  \- org.ow2.asm:asm:jar:5.0.4:runtime
[INFO] |  |  \- org.codehaus.woodstox:woodstox-core-asl:jar:4.4.1:runtime
[INFO] |  |     +- javax.xml.stream:stax-api:jar:1.0-2:runtime
[INFO] |  |     \- org.codehaus.woodstox:stax2-api:jar:3.1.4:runtime
[INFO] |  +- org.springframework.cloud:spring-cloud-starter-archaius:jar:1.1.0.RELEASE:compile
[INFO] |  |  \- commons-configuration:commons-configuration:jar:1.8:compile
[INFO] |  |     +- commons-lang:commons-lang:jar:2.6:compile
[INFO] |  |     \- commons-logging:commons-logging:jar:1.1.1:compile
[INFO] |  +- org.springframework.cloud:spring-cloud-starter-ribbon:jar:1.1.0.RELEASE:compile
[INFO] |  |  +- com.netflix.ribbon:ribbon:jar:2.1.5:compile
[INFO] |  |  |  +- com.netflix.ribbon:ribbon-transport:jar:2.1.5:runtime
[INFO] |  |  |  |  +- io.reactivex:rxnetty-contexts:jar:0.4.9:runtime
[INFO] |  |  |  |  \- io.reactivex:rxnetty-servo:jar:0.4.9:runtime
[INFO] |  |  |  \- io.reactivex:rxnetty:jar:0.4.9:runtime
[INFO] |  |  |     +- io.netty:netty-codec-http:jar:4.0.27.Final:runtime
[INFO] |  |  |     \- io.netty:netty-transport-native-epoll:jar:4.0.27.Final:runtime
[INFO] |  |  |        \- io.netty:netty-common:jar:4.0.27.Final:runtime
[INFO] |  |  +- com.netflix.ribbon:ribbon-core:jar:2.1.5:compile
[INFO] |  |  +- com.netflix.ribbon:ribbon-httpclient:jar:2.1.5:compile
[INFO] |  |  |  \- com.netflix.netflix-commons:netflix-commons-util:jar:0.1.1:runtime
[INFO] |  |  +- com.netflix.ribbon:ribbon-loadbalancer:jar:2.1.5:compile
[INFO] |  |  |  \- com.netflix.netflix-commons:netflix-statistics:jar:0.1.1:runtime
[INFO] |  |  \- io.reactivex:rxjava:jar:1.1.5:compile
[INFO] |  +- com.netflix.ribbon:ribbon-eureka:jar:2.1.5:compile
[INFO] |  \- com.thoughtworks.xstream:xstream:jar:1.4.2:compile
[INFO] |     +- xmlpull:xmlpull:jar:1.1.3.1:compile
[INFO] |     \- xpp3:xpp3_min:jar:1.1.4c:compile

pact-jvm-consumer-junit_2.11

    <dependency>
        <groupId>au.com.dius</groupId>
        <artifactId>pact-jvm-consumer-junit_2.11</artifactId>
        <version>3.3.3</version>
        <scope>test</scope>
    <dependency>

\- au.com.dius:pact-jvm-consumer-junit_2.11:jar:3.3.3:test
[INFO]    +- org.scala-lang:scala-library:jar:2.11.8:test
[INFO]    +- org.scala-lang:scala-compiler:jar:2.11.8:test
[INFO]    |  +- org.scala-lang:scala-reflect:jar:2.11.8:test
[INFO]    |  +- org.scala-lang.modules:scala-xml_2.11:jar:1.0.4:test
[INFO]    |  \- org.scala-lang.modules:scala-parser-combinators_2.11:jar:1.0.4:test
[INFO]    +- com.typesafe.scala-logging:scala-logging_2.11:jar:3.4.0:test
[INFO]    +- au.com.dius:pact-jvm-consumer_2.11:jar:3.3.3:test
[INFO]    |  +- au.com.dius:pact-jvm-model:jar:3.3.3:test
[INFO]    |  |  +- io.netty:netty-handler:jar:4.0.40.Final:runtime
[INFO]    |  |  |  +- io.netty:netty-buffer:jar:4.0.40.Final:runtime
[INFO]    |  |  |  +- io.netty:netty-transport:jar:4.0.40.Final:runtime
[INFO]    |  |  |  \- io.netty:netty-codec:jar:4.0.40.Final:runtime
[INFO]    |  |  +- com.github.zafarkhaja:java-semver:jar:0.9.0:test
[INFO]    |  |  +- org.codehaus.groovy.modules.http-builder:http-builder:jar:0.7.1:test
[INFO]    |  |  |  +- net.sf.json-lib:json-lib:jar:jdk15:2.3:test
[INFO]    |  |  |  |  +- commons-beanutils:commons-beanutils:jar:1.9.2:test
[INFO]    |  |  |  |  \- net.sf.ezmorph:ezmorph:jar:1.0.6:test
[INFO]    |  |  |  +- net.sourceforge.nekohtml:nekohtml:jar:1.9.22:test
[INFO]    |  |  |  |  \- xerces:xercesImpl:jar:2.11.0:test
[INFO]    |  |  |  \- xml-resolver:xml-resolver:jar:1.2:test
[INFO]    |  |  \- com.amazonaws:aws-java-sdk-s3:jar:1.10.30:test
[INFO]    |  |     \- com.amazonaws:aws-java-sdk-kms:jar:1.10.30:test
[INFO]    |  +- au.com.dius:pact-jvm-matchers_2.11:jar:3.3.3:test
[INFO]    |  |  \- io.gatling:jsonpath_2.11:jar:0.6.4:test
[INFO]    |  +- org.codehaus.groovy:groovy-all:jar:indy:2.4.7:test
[INFO]    |  +- com.googlecode.java-diff-utils:diffutils:jar:1.3.0:test
[INFO]    |  +- dk.brics.automaton:automaton:jar:1.11-8:test
[INFO]    |  +- com.github.mifmif:generex:jar:1.0.1:test
[INFO]    |  +- net.databinder:unfiltered-netty-server_2.11:jar:0.8.4:test
[INFO]    |  |  +- net.databinder:unfiltered-netty_2.11:jar:0.8.4:test
[INFO]    |  |  |  \- net.databinder:unfiltered_2.11:jar:0.8.4:test
[INFO]    |  |  \- net.databinder:unfiltered-util_2.11:jar:0.8.4:test
[INFO]    |  \- net.databinder.dispatch:dispatch-core_2.11:jar:0.11.3:test
[INFO]    |     \- com.ning:async-http-client:jar:1.9.11:test
[INFO]    |        \- io.netty:netty:jar:3.10.0.Final:test
[INFO]    \- org.json:json:jar:20140107:test

关于java.lang.NoClassDefFoundError : io/netty/util/concurrent/RejectedExecutionHandlers,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41142910/

相关文章:

python - 如何查看连接到特定 Kafka 主题的(新)消费者

java - Consumers<X> 数组中的 ArrayStoreException

java - 我如何更改 jtabbedpane 选定的选项卡背景颜色

java - GateIn:登录 servlet 的过滤器

performance - 什么可能导致 Kafka `__consumer_offsets` 主题中的巨大负载?

elixir - 如何测试 Elixir GenStage Consumer?

java - AWS Cognito InvalidParameterException clientName必须包含一个方案

java - DataMatrix 支持 UTF8 或 ISO-8859-2 吗?

Java多人服务器阻塞io

Java 8 Lambda 在一次迭代中多次使用一条信息