我正在尝试创建一个Spring Cloud Contract,以在使用Spring Cloud Stream时测试消息。我已经将依赖项包含在pom.xml中。
<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-stream-binder-kafka</artifactId> </dependency> <!--TEST--> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-stream-test-support</artifactId> <scope>test</scope> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-contract-verifier</artifactId> <scope>test</scope> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-stream</artifactId> <type>test-jar</type> <scope>test</scope> <classifier>test-binder</classifier> </dependency>
并配置了合约插件
<!-- Contracts --> <plugin> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-contract-maven-plugin</artifactId> <version>${spring-cloud-contract.version}</version> <extensions>true</extensions> <configuration> <baseClassForTests>com.example.streams.kafkastreamer.KafkaStreamerApplicationTests </baseClassForTests> </configuration> </plugin>
然后,我在本地运行了一个简单的应用程序,以检查一切是否按预期进行。但是,在按documentation创建Spring Cloud Contract测试后,运行生成的测试时出现以下错误
org.springframework.beans.factory.BeanNotOfRequiredTypeException: Bean named 'uppercase-out-0' is expected to be of type 'org.springframework.messaging.PollableChannel' but was actually of type 'org.springframework.cloud.stream.messaging.DirectWithAttributesChannel'
我已经检查过所创建的测试看起来像文档中的那样,并且它确实对我有用
@Test public void validate_consume() throws Exception { // given: ContractVerifierMessage inputMessage = contractVerifierMessaging.create( "[\"MIAU\"]" , headers() .header("sample", "header") ); // when: contractVerifierMessaging.send(inputMessage, "uppercase-in-0"); // then: ContractVerifierMessage response = contractVerifierMessaging.receive("uppercase-out-0"); assertThat(response).isNotNull(); // and: assertThat(response.getHeader("contentType")).isNotNull(); assertThat(response.getHeader("contentType").toString()).isEqualTo("application/json"); // and: DocumentContext parsedJson = JsonPath.parse(contractVerifierObjectMapper.writeValueAsString(response.getPayload())); assertThatJson(parsedJson).field("['attributes']").field("['id']").isEqualTo("com.example.streams.kafkastreamer.KafkaStreamerApplication$$EnhancerBySpringCGLIB$$cf6cc14c2020-03-05T12:07:05.366"); assertThatJson(parsedJson).field("['attributes']").field("['source']").isEqualTo("file:///com/example/streams/kafkastreamer"); assertThatJson(parsedJson).field("['attributes']").field("['specversion']").isEqualTo("1.0"); assertThatJson(parsedJson).field("['attributes']").field("['type']").isEqualTo("My.test.event.type"); assertThatJson(parsedJson).field("['attributes']").field("['datacontenttype']").isEqualTo("application/json"); assertThatJson(parsedJson).field("['attributes']").field("['dataschema']").isNull(); assertThatJson(parsedJson).field("['attributes']").field("['subject']").isNull(); assertThatJson(parsedJson).field("['attributes']").field("['time']").isNull(); assertThatJson(parsedJson).field("['data']").field("['value']").isEqualTo("MIAU"); assertThatJson(parsedJson).field("['dataBase64']").isNull(); assertThatJson(parsedJson).field("['extensions']").field("['specversion']").isEqualTo("1.0"); assertThatJson(parsedJson).array("['extensionsFormats']").isEmpty(); }
在Spring Cloud Contract文档样本中,正在使用jms并将通道设置为
sentTo('jms:output')
。由于我使用的是Spring Cloud Stream Binder,因此要根据我的活页夹的定义将通道的名称设置为sentTo('uppercase-out-0')
。这是我的应用程序属性
?我想我从Spring Cloud Stream或Spring Cloud Contract的官方文档中误解了一些东西,但无法意识到是什么。#stubrunner.integration.enabled: false To make sure is using Spring Cloud Stream spring.cloud.stream.bindings.uppercase-in-0.destination=test spring.cloud.stream.bindings.uppercase-in-0.group=testGroup spring.cloud.stream.bindings.uppercase-out-0.destination=hood spring.cloud.stream.bindings.consume-in-0.destination=hood spring.cloud.stream.bindings.consume-out-0.destination=downtown spring.cloud.function.definition=uppercase;consume
我的问题是,为什么通道大写输出-0没有实现所需的PollableChannel
仅提供更多信息。我的猜测是,自动配置正在配置类型为SpringIntegrationSubMessages
的bean,但应为StreamStubMessages
。但是,我不知道这是怎么发生的或为什么发生的。我猜对了吗?
我正在尝试创建一个Spring Cloud Contract,以在使用Spring Cloud Stream时测试消息。我已经将依赖项包含在pom.xml
该问题来自我的父级测试类配置。在某个时候,我的IDE建议我添加组件扫描,因为没有找到用于