【问题标题】:Spring Cloud Contract producer cannot send messageSpring Cloud Contract 生产者无法发送消息
【发布时间】:2017-09-12 18:05:35
【问题描述】:

我正在尝试将 Spring Cloud Contract 合并到现有项目中。我在 REST 方面取得了一些成功,但我正在努力设置消息传递方面。

到目前为止,我已经在生产者身上建立了一个合同,它确实在 target/generated-test-sources/contracts 中生成了一个测试。我还为测试设置了一个基类。

我无法克服这个错误:

2017-09-08 17:10:51.759 错误 - --[]- [main] o.s.c.c.v.m.stream.StreamStubMessages:尝试解析目标时发生异常。将采用名称 [invites]

org.springframework.beans.factory.NoSuchBeanDefinitionException:没有可用的“org.springframework.cloud.stream.config.ChannelBindingServiceProperties”类型的合格bean 在 org.springframework.beans.factory.support.DefaultListableBeanFactory.getBean(DefaultListableBeanFactory.java:353) 在 org.springframework.beans.factory.support.DefaultListableBeanFactory.getBean(DefaultListableBeanFactory.java:340) 在 org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1093) 在 org.springframework.cloud.contract.verifier.messaging.stream.StreamStubMessages.resolvedDestination(StreamStubMessages.java:86) 在 org.springframework.cloud.contract.verifier.messaging.stream.StreamStubMessages.receive(StreamStubMessages.java:73) 在 org.springframework.cloud.contract.verifier.messaging.stream.StreamStubMessages.receive(StreamStubMessages.java:110) 在 org.springframework.cloud.contract.verifier.messaging.stream.StreamStubMessages.receive(StreamStubMessages.java:36) 在 org.springframework.cloud.contract.verifier.messaging.internal.ContractVerifierMessaging.receive(ContractVerifierMessaging.java:40) 在 org.springframework.cloud.contract.verifier.tests.email.MessagingTest.validate_invitedContract(MessagingTest.java:27)

以后

2017-09-08 17:10:51.759 错误 - --[]- [main] o.s.c.c.v.m.stream.StreamStubMessages:尝试从名为 [invites] 的频道读取消息时发生异常

org.springframework.beans.factory.NoSuchBeanDefinitionException: 没有名为“邀请”的 bean 可用 在 org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:687) 在 org.springframework.beans.factory.support.AbstractBeanFactory.getMergedLocalBeanDefinition(AbstractBeanFactory.java:1207) 在 org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:284) 在 org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202)

我在 src/test/resources 下的 application.yml 文件:

spring: cloud: stream: bindings: output: content-type: application/json destination: invites

我有以下依赖项:

`
    <!-- Spring Cloud Contract Deps -->
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-stream</artifactId>
        <version>1.2.2.RELEASE</version>
    </dependency>       

    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-contract-verifier</artifactId>
        <version>1.1.3.RELEASE</version>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-stream-test-support</artifactId>
        <version>1.2.2.RELEASE</version>
        <scope>test</scope>
    </dependency>
    <!-- END SCC Deps -->`

我梳理了文档,观看了 Marcin 的演讲,并查看了 Spring Cloud Contract 的示例,但我被困住了。任何帮助将不胜感激。

【问题讨论】:

  • 嗨!您可以尝试使用发布火车来管理依赖项吗?还要确保您有 @EnableBindings 注释。此外,很高兴看到您的示例发布在 github 上的某个地方。帮助你会更容易。
  • 嗨马尔辛。使用发布火车已经解决了这个问题。谢谢!
  • 酷,我已经添加了我的答案。你能把它标记为合适的吗?
  • 抱歉,Marcin,我说得太早了。我创建了一个演示项目@github.com/jswaff/scc-demo。我敢肯定我错过了一些简单的东西,但我不能指望它。你介意看看吗?
  • 我已经用缺失的部分更新了我的答案。

标签: spring spring-boot spring-jms spring-cloud-contract


【解决方案1】:

第一期:

请使用发布火车。在发布列车中,我们知道没有无效的依赖项。

第二期:

您没有@EnableBinding(Source.class) 注释。这就是 Stream 不知道如何绑定到 output 频道的原因。

如果您查看 Spring Cloud Contract 示例,您会在主应用程序类 (https://github.com/spring-cloud-samples/spring-cloud-contract-samples/blob/master/producer/src/main/java/com/example/ProducerApplication.java#L9) 上注意到这一行。在我将此行添加到您的代码后,上下文开始,但测试失败,导致消息未发送。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-05-20
    • 1970-01-01
    • 2018-08-29
    • 2018-06-09
    • 2018-11-05
    相关资源
    最近更新 更多