spring-integration:MessageProducer 只能被引用一次 [英] spring-integration: MessageProducer may only be referenced once

查看:40
本文介绍了spring-integration:MessageProducer 只能被引用一次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在多个流中使用网关.我的网关定义是:

I want to use a gateway in multiple flows. My gateway definition is:

@Bean
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public MarshallingWebServiceOutboundGateway myServiceGateway() {
    Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
    marshaller.setPackagesToScan("blah.*");

    MarshallingWebServiceOutboundGateway gateway = new MarshallingWebServiceOutboundGateway(
            serviceEndpoint, marshaller, messageFactory);
    gateway.setMessageSender(messageSender);
    gateway.setRequestCallback(messageCallback);

    return gateway;
}

请注意,我已经在范围原型中定义了消息网关 bean,因此 Spring 应该创建多个网关实例.尽管如此,我还是在启动时收到此消息:

Note that I have defined the message gateway bean in scope prototype so that Spring should create multiple gateway instances. Nevertheless I get this message at startup:

Caused by: java.lang.IllegalArgumentException: A reply MessageProducer may only be referenced once (myServiceGateway) - use @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE) on @Bean definition.

为什么它坚持一个网关不能被多次引用,我如何从多个流中使用同一个网关?

Why does it insist that a gateway must not be referenced more than once and how can I use the same gateway from multiple flows?

使用 spring-integration 5.0.4

Using spring-integration 5.0.4

推荐答案

我觉得你有几次类似 .handle(myServiceGateway()) 的问题.

I thing you have something like .handle(myServiceGateway()) several times.

在这种情况下,您必须从此方法中删除 @Bean@Scope.它也可以是 private.Java DSL 过程将为您创建 bean.每个流都有自己的实例.按照您的要求.

In this case you have to remove @Bean and @Scope from this method. And it also can be just private. The Java DSL process will create beans for you on the matter. And each flow will have its own instance. As you requested.

任何 Spring Integration 组件都不能是 @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE).无论如何,它们是从非原型 bean(endpoints)引用的.因此,本质上,原型 bean 的范围增加了.

Any Spring Integration components can't be @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE) at all. They are referenced from non-prototype beans (endpoints) anyway. So, essentially, the scope of your prototype beans are increased.

这篇关于spring-integration:MessageProducer 只能被引用一次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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