【问题标题】:How to configure a Spring InboundChannelAdapter for Spring XD?如何为 Spring XD 配置 Spring InboundChannelAdapter?
【发布时间】:2016-07-27 00:54:08
【问题描述】:

我有一个想要使用的自定义 Spring XD 源:

   package com.my.springproject;

   import org.springframework.integration.annotation.InboundChannelAdapter;
   import org.springframework.integration.annotation.Poller;

   public class MySource
   {
       @InboundChannelAdapter(value = "output", 
           poller = @Poller(fixedDelay = "5000", maxMessagesPerPoll = "1"))
       public String next() {
           return "foo";
       }
   }

现在的问题是,如何在我的 ModuleConfiguration.java 中注册它,以便 Spring XD 将其识别为有效源?到目前为止,我有这个,但 Source 从来没有记录任何东西。

我的 ModuleConfiguration 如下所示:

package com.my.springproject;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.integration.channel.DirectChannel;
import org.springframework.integration.config.EnableIntegration;
import org.springframework.messaging.MessageChannel;

@Configuration
@EnableIntegration
@ComponentScan( value = { "com.my.springproject" } )
public class ModuleConfiguration {
   @Bean
   MessageChannel output() {
      return new DirectChannel();
   }

      @Bean
   MySource source() {
      return new MySource();
   }
}

【问题讨论】:

    标签: java spring spring-integration spring-xd


    【解决方案1】:

    您必须使用@MessageEndpoint 标记您的MySource,或仅使用@Component

    看起来我们做得有点过头了,MessagingAnnotationPostProcessor 中有这个逻辑:

        if (AnnotationUtils.findAnnotation(beanClass, Component.class) == null) {
            // we only post-process stereotype components
            return bean;
        }
    

    看起来这有点奇怪,不要只扫描 @Bean 上的消息注释。

    请随时就此事提出 JIRA(https://jira.spring.io/browse/INT) 问题!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-01-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-11-05
      • 1970-01-01
      相关资源
      最近更新 更多