我将我的Spring引导版本从2.0.5.RELEASE
升级到2.1.8.RELEASE
(因此Spring Integration从5.0升级到5.1),并且集成流程中的自动类型转换不再起作用。我习惯于定义一组@IntegrationConverter
组件并通过集成流程代码中的操作transform(Type.class, p -> p)
自动转换,但是在新版本中,它似乎已损坏。
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.8.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>org.grorg</groupId>
<artifactId>grointegration</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>grointegration</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-integration</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-ip</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
还有Main.java文件:
package org.grorg.grointegration;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.core.convert.converter.Converter;
import org.springframework.integration.config.IntegrationConverter;
import org.springframework.integration.dsl.IntegrationFlow;
import org.springframework.integration.dsl.IntegrationFlows;
import org.springframework.integration.dsl.Transformers;
import org.springframework.integration.ip.dsl.Tcp;
import org.springframework.stereotype.Component;
class Test {
@Override
public String toString() {
return "test";
}
}
@Component
@IntegrationConverter
class Convert implements Converter<String, Test> {
@Override
public Test convert(String s) {
return new Test();
}
}
@SpringBootApplication
public class Main {
public static void main(String[] args) {
SpringApplication.run(GrointegrationApplication.class, args);
}
@Bean
public IntegrationFlow server() {
return IntegrationFlows
.from(Tcp.inboundGateway(Tcp.netServer(1234)))
.transform(Transformers.objectToString())
.transform(Test.class, id -> id) // in 2.1 I could use .convert(Test.class) but the problem is the same
.log()
.handle((p, h) -> "OK")
.get();
}
}
与外壳一起使用:
telnet localhost 1234
> test
> OK
[...]
在以前的版本(2.0.5.RELEASE)中,程序可以像以前那样很好地工作,但是在新版本(2.1.8.RELEASE)中,我收到此错误(并且没有“ OK”响应):
org.springframework.integration.handler.ReplyRequiredException: No reply produced by handler 'server.org.springframework.integration.config.ConsumerEndpointFactoryBean#1', and its 'requiresReply' property is set to true.
[...]
我发现ConversionService
替换了MessageConverter
,现在杰克逊被用来将消息从一种类型转换为另一种类型。
我在集成流程中错误地使用类型转换吗?您是否有使用新版本投射对象的新解决方案?还是只是回归?
谢谢!
答案 0 :(得分:4)
这是Spring Integration中的错误。
我们只是没有在ConversionService
中使用适当的GenericMessageConverter
。
请对此事提出GH问题。
与此同时,针对您的解决方法是这样的:
@Bean(name = IntegrationContextUtils.ARGUMENT_RESOLVER_MESSAGE_CONVERTER_BEAN_NAME)
public static ConfigurableCompositeMessageConverter configurableCompositeMessageConverter(
@Qualifier(IntegrationUtils.INTEGRATION_CONVERSION_SERVICE_BEAN_NAME) ConversionService conversionService) {
return new ConfigurableCompositeMessageConverter(
Collections.singleton(new GenericMessageConverter(conversionService)));
}
因此,我们将覆盖框架配置的所有内容,并注入IntegrationUtils.INTEGRATION_CONVERSION_SERVICE_BEAN_NAME
组件随附的适当的@IntegrationConverter
bean。