Spring Integration(バージョン4.0.6)を使用した単純なtcpサーバーのjava/annotationベースのxml構成を使用しようとしています。 @MessageEndpointを使って次のように動作しています。問題は何らかの理由で@MessageEndpointでアノテーションされたクラスが静的でなければならないことです。便利なことをするために豆を入れることはできません。 私が理解しているように、@MessageEndpointなしで@ServiceActivatorを使用することは可能ですが、どのように把握できませんでした。Springインテグレーションで@MessageEndpointを指定しない@ServiceActivatorアノテーション設定
これは私が今持っているものです。コメントでは、私が置き換えようとしていたxmlの部分を見ることができます。
@Configuration
@EnableIntegration
public class TcpServerContextConfiguration {
// <int-ip:tcp-connection-factory id="crLfServer"
// type="server"
// port="5678"
// single-use="true"
// so-timeout="10000"/>
@Bean
TcpNetServerConnectionFactory crLfServer() {
TcpNetServerConnectionFactory factory = new TcpNetServerConnectionFactory(5678);
factory.setSingleUse(true);
factory.setSoTimeout(10000);
return factory;
}
// <int-ip:tcp-inbound-gateway id="gatewayCrLf"
// connection-factory="crLfServer"
// request-channel="serverBytes2StringChannel"/>
@Bean
public TcpInboundGateway gatewayCrLf() {
TcpInboundGateway gateway = new TcpInboundGateway();
gateway.setConnectionFactory(crLfServer());
gateway.setRequestChannel(serverBytes2StringChannel());
return gateway;
}
@Bean
public MessageChannel serverBytes2StringChannel() {
return new DirectChannel();
}
// <int:channel id="toSA" />
@Bean
public MessageChannel toSA() {
return new DirectChannel();
}
// <int:service-activator input-channel="toSA"
// ref="echoService"
// method="test"/>
//
// <bean id="echoService"
// class="com.posera.www.poseraStats.site.EchoService" />
@MessageEndpoint
public static class Echo {
@ServiceActivator(inputChannel="toSA")
public String echoService(String req) {
return "echo:" + req;
}
}
// <int:object-to-string-transformer id="serverBytes2String"
// input-channel="serverBytes2StringChannel"
// output-channel="toSA"/>
@Bean
@Transformer(inputChannel="serverBytes2StringChannel", outputChannel="toSA")
public org.springframework.integration.transformer.Transformer serverBytes2String() {
return new ObjectToStringTransformer();
}
}
は、だから私は@MessageEndpointと、次のコードを試してみましたが、それは失敗します。
@Bean
@ServiceActivator(inputChannel="toSA")
public MessageHandler newEchoService() {
}
しかし、私:私は、私がすべきこのような何かを探しています答えを推測
@ServiceActivator(inputChannel="toSA")
public String echoService(String req) {
return "echo:" + req;
}
この時点でString型の入力チャンネルに使用する必要があるMessageHandlerインターフェイスの実装がわからない場合
ありがとうございます。
こんにちはゲイリー、このような迅速な答えに感謝します。私はあなたがそれに答えるだろうという気持ちを持っていました:) – Yerke
TcpServerContextConfigurationに '@ MessageEndpoint'を追加すると助けになりました。どうもありがとう。しかし、将来の私の理解のために、私が質問で説明したように、 '@ MessageAndpoint'を使わずに' @ ServiceActivator'を使う方法がありますか? – Yerke
私は '@ MessageEndpoint'は4.3以降では必要なくなったと言っています。その前に、それはPOJO '@ ServiceActivator'に必要でした。 '@Bean'スタイルの' @ServiceActivator'は 'MessageHandler'型でなければなりません。そのスタイルを使用するには、 'AbstractReplyProducingMessageHandler'をサブクラス化し、' handleRequestMessage() 'を実装する必要があります。出力チャネルはハンドラで指定する必要があり、 '@ ServiceActivator'では指定しないでください。コンシューマーエンドポイントとハンドラーの2つのBeanがあります。 [the documentation](http://docs.spring.io/spring-integration/reference/html/configuration.html#annotations_on_beans)を参照してください。 –