2016-12-15 9 views
1

古いバージョンのSpring(XML設定を使用)で作成したプロジェクトをSpringのBoot(Java configを使用)に移行しようとしています。 プロジェクトでは、JMSとAMQPによる通信にSpring Integrationを使用しています。私の知る限り理解されるように、私は、インターフェイスが、それは私がアクセスすることはできませんライブラリに配置され、今使用中であることを、外部インターフェースの "@MessagingGateway"アノテーション

<int:gateway id="someID" service-interface="MyMessageGateway" 
default-request-channel="myRequestChannel" 
default-reply-channel="myResponseChannel" 
default-reply-timeout="20000" /> 

@MessagingGateway(name="someID", defaultRequestChannel = "myRequestChannel", 
defaultReplyChannel = "myResponseChannel", defaultReplyTimeout = "20000") 
public interface MyMessageGateway{ ...... } 

私の問題があると交換する必要があり。

このインターフェイスをMessagingGatewayとしてどのように定義できますか?

ありがとうございます!

+0

あなたは何もする必要はありませんあなたはまだXML設定を使用することができます...は、Javaベースの構成にすべてを移行する必要はありません。 –

+0

これは正しいことですが、Spring Bootでは必要ありません。しかし、この部門はJavaベースの設定に切り替える必要があります。 :) – NagelAufnKopp

答えて

0

:ここに簡単な例ですつまり

interface IControlBusGateway { 

    void send(String command); 
} 

@MessagingGateway(defaultRequestChannel = "controlBus") 
interface ControlBusGateway extends IControlBusGateway { 

} 

... 


@Autowired 
private IControlBusGateway controlBus; 

... 

try { 
     this.bridgeFlow2Input.send(message); 
     fail("Expected MessageDispatchingException"); 
    } 
    catch (Exception e) { 
     assertThat(e, instanceOf(MessageDeliveryException.class)); 
     assertThat(e.getCause(), instanceOf(MessageDispatchingException.class)); 
     assertThat(e.getMessage(), containsString("Dispatcher has no subscribers")); 
    } 
    this.controlBus.send("@bridge.start()"); 
    this.bridgeFlow2Input.send(message); 
    reply = this.bridgeFlow2Output.receive(5000); 
    assertNotNull(reply); 

することができますちょうどextendsそのローカルの1の外部インタフェース。 GatewayProxyFactoryBeanはあなたのためにプロキシマジックを下にします。

また、我々は、同様のユースケースのために、このJIRAを持っている:https://jira.spring.io/browse/INT-4134

+0

それはトリックでした!とても小さくてシンプル。 :)ありがとう! – NagelAufnKopp

0

GatewayProxyFactoryBeanを使用してください。私はこのトリックをテストしている

@SpringBootApplication 
public class So41162166Application { 

    public static void main(String[] args) { 
     ConfigurableApplicationContext context = SpringApplication.run(So41162166Application.class, args); 
     context.getBean(NoAnnotationsAllowed.class).foo("foo"); 
     context.close(); 
    } 

    @Bean 
    public GatewayProxyFactoryBean gateway() { 
     GatewayProxyFactoryBean gateway = new GatewayProxyFactoryBean(NoAnnotationsAllowed.class); 
     gateway.setDefaultRequestChannel(channel()); 
     return gateway; 
    } 

    @Bean 
    public MessageChannel channel() { 
     return new DirectChannel(); 
    } 

    @ServiceActivator(inputChannel = "channel") 
    public void out(String foo) { 
     System.out.println(foo); 
    } 

    public static interface NoAnnotationsAllowed { 

     public void foo(String out); 

    } 

} 
関連する問題