评估异常:此命令处理器不支持“启动”方法

我想使用 spring 集成开发控制总线示例。

我决定做同样的事情,但使用 java DSL。

现在我有以下源代码:

@Configuration

@EnableIntegration

@IntegrationComponentScan

public class Config {


    @Bean

    public IntegrationFlow controlBusFlow() {

        return IntegrationFlows.from("operationChannel")

                .controlBus()

                .get();

    }


    @Bean

    @InboundChannelAdapter(channel = "adapterOutputChanel", autoStartup = "false", poller = @Poller(fixedDelay = "1000"))

    public MessageSource<String> inboundAdapter() {

        return new MessageSource<String>() {


            @Override

            public Message receive() {

                return new Message() {

                    @Override

                    public String getPayload() {

                        return "some_output_message";

                    }


                    @Override

                    public MessageHeaders getHeaders() {

                        return null;

                    }

                };

            }

        };

    }


    @Bean

    public AbstractMessageChannel adapterOutputChanel() {

        return new QueueChannel();

    }


}

和应用:


@SpringBootApplication

public class MyApplication {

    public static void main(String[] args) {

        ConfigurableApplicationContext ctx = new SpringApplication(MyApplication.class).run(args);

        MessageChannel controlChannel = ctx.getBean("operationChannel", MessageChannel.class);

        PollableChannel adapterOutputChanel = ctx.getBean("adapterOutputChanel", PollableChannel.class);

        controlChannel.send(new GenericMessage<String>("@inboundAdapter.start()"));

        adapterOutputChanel.receive(1000);

    }

}

我有什么错吗?



郎朗坤
浏览 116回答 1
1回答

红颜莎娜

根据Spring中的Java和Annotation配置,inboundAdapterbean名称(本质上是bean方法名称)被准确地分配给您声明为bean的内容。在您的情况下,它是一个MessageSource实现。您确实需要在控制总线命令中处理通过那个SourcePollingChannelAdapter分配给您的 bean 。唯一的问题是我们需要找出一个正确的 bean 名称以从命令中引用它:MessageSource@InboundChannelAdapterAbstractEndpoint bean 名称使用以下模式生成:[configurationComponentName].[methodName].[decapitalizedAnnotationClassShortName]。例如,前面显示的 consoleSource() 定义的 SourcePollingChannelAdapter 端点获取 myFlowConfiguration.consoleSource.inboundChannelAdapter 的 bean 名称。另请参见端点 Bean 名称。因此,我建议您参考端点 Bean 名称@EndpointId建议,并与它一起使用@InboundChannelAdapter:@Bean@InboundChannelAdapter(channel = "adapterOutputChanel", autoStartup = "false", poller = @Poller(fixedDelay = "1000"))@EndpointId("myInboundAdapter")public MessageSource<String> inboundAdapter() {因此,您的控制总线命令将如下所示:"@myInboundAdapter.start()"更新用于连接的 Java DSL 变体MessageSource:@Beanpublic IntegrationFlow channelAdapterFlow() {    return IntegrationFlows.from(new MyMessageSource(),                 e -> e.id("myInboundAdapter").autoStartup(false).poller(p -> p.fixedDelay(100)))            .channel(adapterOutputChanel())            .get();}
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java