gpt4 book ai didi

java - 如何为 Spring XD 配置 Spring InboundChannelAdapter?

转载 作者:行者123 更新时间:2023-11-30 10:46:36 26 4
gpt4 key购买 nike

我有一个要使用的自定义 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();
}
}

最佳答案

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

看起来我们有点过头了,在 MessagingAnnotationPostProcessor 中有这样的逻辑:

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

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

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

关于java - 如何为 Spring XD 配置 Spring InboundChannelAdapter?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36454204/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com