我目前正在使用citrus-framework来测试一个应用程序。我的一个接口使用Protobuf,我想实现一个与spring集成兼容的protobuf- to -json-transformer,类似于下面的用法,但使用我的transformer而不是object- to -string-string:
<int:channel id="configRawReplies" />
<int:object-to-string-transformer id="configtransformer" input-channel="configRawReplies" output-channel="configResponse" />
<int:channel id="configResponse">
<int:queue />
</int:channel>现在我有一个和object-to-string-transformer一模一样的原型,我用以下命令加载:
<bean id="Proto2Json" class="com.nobody.citrus.transformer.ProtoToJSONString">
<property name="input-channel" value="none"/>
<property name="output-channel" value="none"/>
</bean>但它失败了。
Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'Proto2Json' defined in URL [file:/Users/nobody/DevOops/test/citrus-scala/target/test-classes/citrus-context.xml]:
Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException:
Invalid property 'input-channel' of bean class [com.pme.citrus.transformer.ProtoToJSONString]:
Bean property 'input-channel' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?有没有人有办法或提示在网上找什么地方?
BR
发布于 2019-01-07 23:13:13
是这样的。您确实需要遵循ObjectToStringTransformer中的设计来实现您自己的AbstractPayloadTransformer。在您的应用程序上下文中,它必须是一个普通的<bean>定义。
唯一的问题是,你不明白为什么我们真的有那么多自定义标记来利用input-channel和output-channel属性。例如,这个<int:object-to-string-transformer>为应用程序上下文提供了几个bean,包括前面提到的ObjectToStringTransformer实例、一个MessageTransformingHandler,最后是连接MessageHandler和inputChannel的ConsumerEndpointFactoryBean。
因此,这里缺少的是自定义AbstractPayloadTransformer实现的通用<int:transformer>定义:
<bean id="Proto2Json" class="com.nobody.citrus.transformer.ProtoToJSONString"/>
<int:tranformer ref="Proto2Json" input-channel="configRawReplies" output-channel="configResponse"/>请阅读更多参考手册,以避免将来进行类似的讨论:
https://docs.spring.io/spring-integration/reference/html/overview.html#programming-tips
https://docs.spring.io/spring-integration/reference/html/messaging-transformation-chapter.html
https://stackoverflow.com/questions/54076591
复制相似问题