Spring Integration Java Dsl中有没有办法做到这一点:

@Bean
IntegrationFlow serviceFlow() {
    return IntegrationFlows
        .from("inputChannel")
        .handle(File.class, (p,h) -> someService.someMethod(p))
        .channel("someChannel")
        .get();
}


表现如下:

@Bean
IntegrationFlow serviceFlow() {
    return IntegrationFlows
        .from("inputChannel")
        .handle("someService","someMethod")
        .channel("someChannel")
        .get();
}


当涉及到异常处理时?

第一版抛出:

2015-06-03 23:30:42.912 ERROR 6251 --- [ask-scheduler-1] o.s.integration.handler.LoggingHandler   : org.springframework.messaging.MessageHandlingException: ; nested exception is java.lang.reflect.InvocationTargetException
at org.springframework.integration.dsl.LambdaMessageProcessor.processMessage(LambdaMessageProcessor.java:129)
at org.springframework.integration.handler.ServiceActivatingHandler.handleRequestMessage(ServiceActivatingHandler.java:71)
(...)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
(...)
Caused by: java.lang.RuntimeException: error from service
at com.lukzar.SomeService.someMethod(SomeService.java:15)
at com.lukzar.IntegrationConfiguration.lambda$serviceFlow$1(IntegrationConfiguration.java:48)
at com.lukzar.IntegrationConfiguration$$Lambda$2/1367672657.handle(Unknown Source)
(...)


带有beanName和methodName的版本会抛出:

2015-06-03 23:27:45.841 ERROR 6177 --- [ask-scheduler-1] o.s.integration.handler.LoggingHandler   : org.springframework.messaging.MessageHandlingException: ; nested exception is java.lang.RuntimeException: error from service
at org.springframework.integration.handler.MethodInvokingMessageProcessor.processMessage(MethodInvokingMessageProcessor.java:78)
at org.springframework.integration.dsl.support.BeanNameMessageProcessor.processMessage(BeanNameMessageProcessor.java:57)
(...)
Caused by: java.lang.RuntimeException: error from service
at com.lukzar.SomeService.someMethod(SomeService.java:15)
(...)

最佳答案

如果按照“行为”的意思是使error from service异常成为第一个cause,那么我们可以考虑从堆栈跟踪中删除InvocationTargetException。这将使基础异常成为MessageHandlingExceptioncause

如果要使堆栈跟踪绝对相同,则不行。

如果您是指前者,请在JavaDSL组件上打开JIRA Issue,我们来看一下。

09-26 05:20