5

指定した後でも以下の例外が発生するのはなぜですかrequires-reply="false"

例外

org.springframework.integration.support.channel.ChannelResolutionException: 利用可能な output-channel または replyChannel ヘッダーがありません

設定

<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:int="http://www.springframework.org/schema/integration"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
        http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration-2.1.xsd">

    <int:channel id="inChannel">

    </int:channel>

    <bean id="upperService" class="sipackage.service.UppercaseService"></bean>

    <int:service-activator requires-reply="false" input-channel="inChannel" ref="upperService" method="toUpper"></int:service-activator>
</beans>

JUnit

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations={"/META-INF/spring/integration/sample.xml"})
public class ChannelTest {

    @Autowired MessageChannel inChannel;

    @Test
    public void test() {

        boolean sendOutcome=inChannel.send(MessageBuilder.withPayload("Hello, there 1!").build());
        assertTrue(sendOutcome);

        sendOutcome=inChannel.send(MessageBuilder.withPayload("Hello, there 2!").build());
        assertTrue(sendOutcome);
    }

}

サービス

public class UppercaseService {

public String toUpper(String msg)
{
    return msg.toUpperCase();
}
}
4

3 に答える 3

10

「サービスアクティベーターの設定」に従って:

サービス メソッドが null 以外の値を返すと、エンドポイントは応答メッセージを適切な応答チャネルに送信しようとします。応答チャネルを決定するために、エンドポイント構成で「出力チャネル」が提供されているかどうかを最初に確認します...「出力チャネル」が使用できない場合は、メッセージの replyChannel ヘッダー値を確認します。

言及されていないのは、応答を生成するメッセージ ハンドラーの基本的な動作は、これら 2 つのチェックで何も見つからない場合、例外をスローするということです。 AbstractReplyProducingMessageHandler は、そのような多くのものによって共有される基本クラスです。したがって、void 以外のサービス メソッドがある場合は、メッセージに output-channel または replyChannel ヘッダーを設定する必要があります。

SI 担当者が提案するオプションの 1 つは、replyChannel ヘッダーを「nullChannel」に設定するサービス アクティベーターの前にヘッダー エンリッチャーを配置することです。ヘッダーはデフォルトでは上書きされないため、既存の replyChannel は意図したとおりに機能し、それ以外はすべて nullChannel にダンプされます。

nullrequires-reply 属性に関しては、有効なメッセージの代わりに生成される可能性のあるコンポーネントがある場合に、まったく別の問題を処理するためのものです。このフラグを使用すると、null応答を例外にする必要があることを示すことができます。これについては、 「メッセージング ゲートウェイのエラー処理」「応答がない場合のゲートウェイの動作」の注を参照してください。

于 2013-01-25T04:20:29.457 に答える
7

requires-reply="false"void「返すように定義されていないメソッドが返されても問題ない」という意味ですnull

メソッドが応答を返す場合、それを送信する場所が必要です。前述guidoのように、結果を無視する場合は、output-channelを nullChannel に設定します。

于 2013-01-25T04:17:36.667 に答える
0

属性: 返信が必要

サービス メソッドが null 以外の値を返す必要があるかどうかを指定します。この値はデフォルトで「false」になりますが、「true」に設定すると、基礎となるサービス メソッド (または式) が null 値を返したときに ReplyRequiredException がスローされます。

于 2015-06-16T16:05:56.307 に答える