gpt4 book ai didi

java - Spring Integration Java Config/DSL 中没有方法的服务激活器

转载 作者:行者123 更新时间:2023-11-29 03:04:23 25 4
gpt4 key购买 nike

当为 service-activator 使用基于 XML 的配置时,您可以排除 method,如下所示:

<service-activator input-channel="incomingCustomerChannel" output-channel="outgoingCustomerChannel" ref="customerService" />

这将导致 SI 框架根据负载选择 customerService 中的目标方法。如何使用 DSL 和 Java 配置实现相同的功能?

目前我有以下内容:

@Bean
public IntegrationFlow customerRequestFlow(ConnectionFactory connectionFactory) {

return IntegrationFlows.from((MessagingGateways g) -> g.jms(connectionFactory)
.correlationKey("JmsCorrelationID")
.destination("customer_incoming.queue"))
.handle("customerService", "addCustomer")
.get();
}

服务激活器定义为:

@Component
public class customerService {

@ServiceActivator
public AddCustomerResponse addCustomer(AddCustomerRequest addCustomerRequest) {

// add customer
}
}

我扩展了激活器以添加一个 deleteCustomer 方法,如下所示:

@Component
public class customerService {

@ServiceActivator
public AddCustomerResponse addCustomer(AddCustomerRequest request) {

// add customer
}

@ServiceActivator
public DeleteCustomerResponse deleteCustomer(DeleteCustomerRequest request) {

// delete customer
}
}

我不能简单地从 .handle("customerService", "addCustomer") 中删除 , "addCustomer",因为 methodName 是必需的。是否可以在 Java 配置/DSL 中实现这一点?

最佳答案

您可以使用相同的 .handle()使用 null对于方法名称:

.handle("customerService", "addCustomer")

或以 version 1.1 开头您可以使用该方法的新版本:

@Autowired
private CustomerService customerService;
....
.handle(this.customerService)

这两种变体的功能与您使用 ref 时的功能完全相同对于 <service-activator> .

关于java - Spring Integration Java Config/DSL 中没有方法的服务激活器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32798938/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com