如何在服务激活器中将有效负载设置为构造函数参数值 [英] How to set payload as constructor-arg value in service-activator

查看:32
本文介绍了如何在服务激活器中将有效负载设置为构造函数参数值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经开始使用 SI,现在有点卡住了,因为我们想在我们现有的项目之一中使用 SI,避免尽可能地进行更改.

I've started with SI and kind of stuck right now as we want to use SI in one of our existing project avoiding changes where we can.

我们将用作服务激活器的 bean 接受 java 对象的构造函数参数.

A bean which we would be using as a service activator accepts an constructor argument of a java object.

该对象在有效负载中,但随后我无法使用 service-activator 的内部 bean 使用来设置它

that object is in the payload but then I'm unable to set it using inner bean usage of service-activator

<service-activator input-channel="ADMIN_TEST_CONNECTION" method="testConnection">
  <beans:bean class="mypackage.request.AdminRequestProcessor">
                <beans:constructor-arg value="payload"/>
            </beans:bean>
 </service-activator>

它在抱怨无法将 [java.lang.String] 类型的参数值转换为所需类型.

it's complaining about Could not convert argument value of type [java.lang.String] to required type.

请帮助了解如何访问有效负载并将其设置为构造函数参数.

Please help in how to access payload and set it as an constructor argument.

如果我通过非构造函数 arg 路由并更改现有的 java 对象,那么它可以在服务激活器中使用此调用

If I go via non- constructor arg route and change existing java object then it works with this call in the service activator

expression="@bean.testConnection(payload)"/>

expression="@bean.testConnection(payload)"/>

但我不希望您更改现有的 Java 代码,除非别无他法.

but I don't wish you to change the existing java code until there is no other way.

推荐答案

我认为除非更改某些内容或添加现有代码,否则您别无选择.

I think you don't have choice unless change something or add code around existing.

Service-Activator 针对 input-channel 中的每个传入消息执行其功能.该功能正是方法调用,其中 Message 用作方法参数的上下文.

Service-Activator performs its functionality against each incoming message in the input-channel. And that functionality is exactly method invocation where Message is used as a context for method arguments.

不确定您将如何处理该有效负载,但使用像您的 AdminRequestProcessor 这样的有状态对象看起来并不正确.只是不要忘记,您可能有很多传入的消息,但 service-activator 应该保持一致.

Not sure what you are going to do with that payload, but that doesn't look correct to use statefull object like your AdminRequestProcessor. Just don't forget that you may have many incoming message, but service-activator should be consistent.

另外不要忘记 singleton,所以你的 AdminRequestProcessor 只被实例化一次.

Plus don't forget that <beans:bean> is singleton, so your AdminRequestProcessor is instantiated only once.

查看您的示例,我建议如下:

Looking to your sample I'd suggest something like this:

expression="new AdminRequestProcessor(payload).testConnection()"/>

如果您真的不想更改代码中的任何内容.

If you really don't want to change anything in your code.

您可以在 参考手册.

这篇关于如何在服务激活器中将有效负载设置为构造函数参数值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆