Spring Integration 5.1 - 使用@IntegrationConverter 的集成流转换不起作用
Spring Integration 5.1 - integration flow convertion with @IntegrationConverter doesn't work
我将 Spring 引导版本从 2.0.5.RELEASE
升级到 2.1.8.RELEASE
(因此 Spring 集成从 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();
}
}
与shell一起使用:
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
取代,现在 Jackson 用于将消息从一种类型转换为另一种类型。
我是否错误地使用了集成流程的类型转换?您有新版本的铸造对象的新解决方案吗?或者这只是一种倒退?
提前致谢!
这是 Spring 集成中的错误。
我们只是没有在 GenericMessageConverter
.
中使用正确的 ConversionService
请就此事提出 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
bean,它随 @IntegrationConverter
组件一起提供。
我将 Spring 引导版本从 2.0.5.RELEASE
升级到 2.1.8.RELEASE
(因此 Spring 集成从 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();
}
}
与shell一起使用:
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
取代,现在 Jackson 用于将消息从一种类型转换为另一种类型。
我是否错误地使用了集成流程的类型转换?您有新版本的铸造对象的新解决方案吗?或者这只是一种倒退?
提前致谢!
这是 Spring 集成中的错误。
我们只是没有在 GenericMessageConverter
.
ConversionService
请就此事提出 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
bean,它随 @IntegrationConverter
组件一起提供。