Spring Integration Java Config / DSL中没有方法的Service Activator

时间:2015-09-26 15:47:29

标签: java spring spring-integration

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
    }
}

我不能简单地从, "addCustomer"移除.handle("customerService", "addCustomer"),因为methodName是强制性的。是否有可能在Java config / DSL中实现这一点?

1 个答案:

答案 0 :(得分:3)

您可以使用.handle()使用null作为方法名称:

.handle("customerService", "addCustomer")

或者从version 1.1开始,您可以使用该方法的新版本:

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

这两种变体与ref的{​​{1}}完全相同。