Spring integration Kotlin Java DSL:从字节[]转换为字符串
我正在将Spring集成的Spring integration Kotlin Java DSL:从字节[]转换为字符串,spring-integration,Spring Integration,我正在将Spring集成的tcp客户机服务器示例转换为使用JavaDSL和Kotlin 在我的入站TCP服务器中,我需要将来自通道的字节[]转换为我的echo服务的字符串 这是我当前的流定义: @EnableIntegration @IntegrationComponentScan @Configuration class ClientServerDemoConfig { @MessagingGateway(defaultRequestChannel = "input", name = "gw
tcp客户机服务器示例转换为使用JavaDSL和Kotlin
在我的入站TCP服务器中,我需要将来自通道的字节[]
转换为我的echo服务的字符串
这是我当前的流定义:
@EnableIntegration
@IntegrationComponentScan
@Configuration
class ClientServerDemoConfig {
@MessagingGateway(defaultRequestChannel = "input", name = "gw")
interface SimpleGateway {
fun send(text: String): String
}
@Bean
fun outboundTCP() =
IntegrationFlows.from("input")
.handle(Tcp.outboundGateway(TcpNetClientConnectionFactory("127.0.0.1", 7777)))
.get()
@Bean
fun inboundTCP() =
IntegrationFlows.from(Tcp.inboundGateway(TcpNetServerConnectionFactory(7777)))
.transform<Array<Byte>, String> { p -> String(p.toByteArray()) }
.handle(EchoService(), "test")
.get()
奇怪的是,在调试时,我可以看到正在执行的转换器,但随后我陷入了试图找出它为什么不工作的细节中
有人能告诉我我没有做什么或做错了什么吗
谢谢
dependencies {
compile('org.springframework.boot:spring-boot-starter-integration')
compile('org.springframework.integration:spring-integration-ip')
compile("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
compile("org.jetbrains.kotlin:kotlin-reflect")
runtime('org.springframework.boot:spring-boot-devtools')
testCompile('org.springframework.boot:spring-boot-starter-test')
}
堆栈跟踪:
2018-07-10 16:53:59.726 ERROR 20187 --- [ restartedMain] o.s.boot.SpringApplication : Application run failed
java.lang.IllegalStateException: Failed to execute CommandLineRunner
at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:800) [spring-boot-2.0.3.RELEASE.jar:2.0.3.RELEASE]
at org.springframework.boot.SpringApplication.callRunners(SpringApplication.java:781) [spring-boot-2.0.3.RELEASE.jar:2.0.3.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:335) [spring-boot-2.0.3.RELEASE.jar:2.0.3.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1255) [spring-boot-2.0.3.RELEASE.jar:2.0.3.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1243) [spring-boot-2.0.3.RELEASE.jar:2.0.3.RELEASE]
at alwyn.tcpclientserver.ClientServerDemoApplicationKt.main(ClientServerDemoApplication.kt:29) [main/:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_161]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_161]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_161]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_161]
at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49) [spring-boot-devtools-2.0.3.RELEASE.jar:2.0.3.RELEASE]
Caused by: org.springframework.beans.ConversionNotSupportedException: Failed to convert value of type 'byte[]' to required type 'java.lang.String'; nested exception is java.lang.IllegalStateException: Cannot convert value of type 'byte[]' to required type 'java.lang.String': no matching editors or conversion strategy found
at org.springframework.beans.TypeConverterSupport.doConvert(TypeConverterSupport.java:77) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
at org.springframework.beans.TypeConverterSupport.convertIfNecessary(TypeConverterSupport.java:44) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
at org.springframework.integration.gateway.GatewayProxyFactoryBean.convert(GatewayProxyFactoryBean.java:763) ~[spring-integration-core-5.0.6.RELEASE.jar:5.0.6.RELEASE]
at org.springframework.integration.gateway.GatewayProxyFactoryBean.invokeGatewayMethod(GatewayProxyFactoryBean.java:532) ~[spring-integration-core-5.0.6.RELEASE.jar:5.0.6.RELEASE]
at org.springframework.integration.gateway.GatewayProxyFactoryBean.doInvoke(GatewayProxyFactoryBean.java:469) ~[spring-integration-core-5.0.6.RELEASE.jar:5.0.6.RELEASE]
at org.springframework.integration.gateway.GatewayProxyFactoryBean.invoke(GatewayProxyFactoryBean.java:460) ~[spring-integration-core-5.0.6.RELEASE.jar:5.0.6.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185) ~[spring-aop-5.0.7.RELEASE.jar:5.0.7.RELEASE]
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:212) ~[spring-aop-5.0.7.RELEASE.jar:5.0.7.RELEASE]
at com.sun.proxy.$Proxy60.send(Unknown Source) ~[na:na]
at alwyn.tcpclientserver.ClientServerDemoApplication.run(ClientServerDemoApplication.kt:19) ~[main/:na]
at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:797) [spring-boot-2.0.3.RELEASE.jar:2.0.3.RELEASE]
... 10 common frames omitted
Caused by: java.lang.IllegalStateException: Cannot convert value of type 'byte[]' to required type 'java.lang.String': no matching editors or conversion strategy found
at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:299) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:99) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
at org.springframework.beans.TypeConverterSupport.doConvert(TypeConverterSupport.java:73) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
... 20 common frames omitted
TCP/IP实际上是一个byte[]
协议,因此很自然地,这种类型将被发送到出站端,并从入站端接收
对于您的fun发送(text:String):String
gateway合同,在通过Tcp.outboundGateway()
收到回复后,您确实需要添加byte[]->String
转换/转换。因此,要为您的客户解决此问题,您需要在客户端具有类似的功能:
@Bean
fun outboundTCP() =
IntegrationFlows.from("input")
.handle(Tcp.outboundGateway(TcpNetClientConnectionFactory("127.0.0.1", 7777)))
.transform(Transformers.objectToString())
.get()
我认为,IllegalStateException
来自其他地方,而不是您的.transform()
。请与我们共享一个完整的堆栈跟踪,以便更好地了解整个情况。当我在启用spring boot调试的情况下运行时,它会检查条件,并出于某种原因抱怨FailureAnalyzer org.springframework.boot.autoconfigure.jdbc。HikariDriverConfigurationFailureAnalyzer@3b8f5ed失败,但是我在build.gradle.Well中没有提到spring数据、jdbc或任何与sql相关的内容。这绝对与.transform()
无关。请不要在一个问题中混入顾虑。让我们专注于报告的问题!好的,我将为转换和依赖项添加完整的堆栈跟踪。???不,我说的是一个异常堆栈跟踪。我不需要你的依赖。您只需要从日志中显示更多关于IllegalStateException
@Bean
fun outboundTCP() =
IntegrationFlows.from("input")
.handle(Tcp.outboundGateway(TcpNetClientConnectionFactory("127.0.0.1", 7777)))
.transform(Transformers.objectToString())
.get()