How to set payload as constructor-arg value in service-activator

风流意气都作罢 提交于 2020-01-25 16:20:25

问题


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.

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

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>

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.

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)"/>

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


回答1:


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

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.

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.

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.

Everything rest you can find in the Reference Manual.



来源:https://stackoverflow.com/questions/39044107/how-to-set-payload-as-constructor-arg-value-in-service-activator

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!