Spring 如何在ServiceActivator中读取头值以动态解析方法
我浏览了一篇spring博客,其中解释了如何使用groovy动态路由 我正在上一个service activator中设置Spring 如何在ServiceActivator中读取头值以动态解析方法,spring,spring-integration,Spring,Spring Integration,我浏览了一篇spring博客,其中解释了如何使用groovy动态路由 我正在上一个service activator中设置方法标题值 <int:service-activator input-channel="routingChannel" output-channel="headerRouter" ref="routingHelper" method="headers['method']"> </int:service-activator>
方法
标题值
<int:service-activator input-channel="routingChannel"
output-channel="headerRouter" ref="routingHelper" method="headers['method']">
</int:service-activator>
我试过了
expression=“@beanFactory.getBean('routingHelper').routeMe()
也不工作请帮助我获取配置xml中的标题值。这样不行 您只能在
方法参数bean定义阶段表达式中使用。这一个(headers['method'
)运行时类型,可以从表达式
word中的那些属性中使用。但它无论如何都不会有帮助:SpEL没有按名称调用方法的表示法
从另一方面来说,我们需要理解你们的逻辑。若你们最终得到了反射,那个么为什么要按方法名路由呢
为什么不使用单一方法和if…else
inside?或者路由到不同的bean呢
即使使用Groovy动态方法调用,我们也会得到反射:
routingHelper.'headers[method]'(payload)
嗨,阿泰姆,谢谢你的回复:)我阅读了spring论坛的线程,它解释了动态调用service activator,service activator input channel=“inputChannel”output channel=“outputChannel”expression=“@beanFactory.getBean(headers.serviceIdentifier+'service')。执行(headers,payload)“/但它也抛出错误:@beanFactory.getBean(headers.method).routeMe(有效负载):嵌套异常为org.springframework.expression.AccessException:无法解析对BeanFactory的bean引用这是正确的,因为您尝试从此头调用某些内容。方法,其中它只是方法名称,但您需要该方法的确切服务,对于您的所有特定服务,它可以是相同的相同的接口。