有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

spring集成路由器中的java异常处理

我是集成方面的新手。我有一个路由器。在特定场景中,该方法引发异常。基于该异常,我如何路由我的消息。我希望捕获该异常,并基于将我的消息路由到另一个示例频道

<integration:router ref="serviceImpl" method="getName"/>

共 (1) 个答案

  1. # 1 楼答案

    您可以尝试以下方法:

    首先,按照以下方式配置路由器和bean:

    <integration:router ref="serviceImpl" method="getName"/>
    <beans:bean class="com.test.ServiceImpl" id="serviceImpl">
    </beans:bean>
    </int:router>
    

    那么您的ServiceImpl.java应该如下所示:

     public class ServiceImpl {
    
         public String getName(Name name) {
    
          String channel = "";
    
          try {
           //Your business validations should be here and if everything is okay, then route the message to some channel
           channel = "goToSomeChannel"
          } catch (SomeException e) {
           //You got the exception, So route to different channel
           channel = "goToSomethingElseChannel";
          }
    
          return channel;
         }
    
    
    }
    

    最后,在spring集成配置文件中定义通道goToSomeChannelgoToSomethingElseChannel