如何为 Spring XD 配置 Spring InboundChannelAdapter?

How to configure a Spring InboundChannelAdapter for Spring XD?

我有一个要使用的自定义 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 从来没有记录任何东西。

我的模块配置如下所示:

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();
   }
}

您必须用 @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) 问题!