【问题标题】:Spring Integration DSL reference documentation code example doesn't compileSpring Integration DSL 参考文档代码示例无法编译
【发布时间】:2021-07-15 21:05:06
【问题描述】:

Spring Integration DSL 官方参考文档在https://docs.spring.io/spring-integration/reference/html/dsl.html#java-dsl第一部分提供了如下代码示例

@Configuration
@EnableIntegration
public class MyConfiguration {

    @Bean
    public AtomicInteger integerSource() {
        return new AtomicInteger();
    }

    @Bean
    public IntegrationFlow myFlow() {
        return IntegrationFlows.from(integerSource::getAndIncrement,
                c -> c.poller(Pollers.fixedRate(100)))
                .channel("inputChannel")
                .filter((Integer p) -> p > 0)
                .transform(Object::toString)
                .channel(MessageChannels.queue())
                .get();
    }
}

当我将此代码复制粘贴到我的 IDE (IntelliJ) 中时,我在这一行收到以下错误

        return IntegrationFlows.from(integerSource::getAndIncrement,

错误信息:

Cannot resolve symbol 'integerSource'

我尝试了各种将 getAndIncrement 定义为 messageSource 的替代方法,但到目前为止,它们都产生了某种错误。

有没有办法让这个例子编译和运行?

【问题讨论】:

    标签: spring-integration spring-integration-dsl


    【解决方案1】:

    我们最近发现了同样的问题。请参阅最新快照中的固定文档:https://docs.spring.io/spring-integration/docs/5.5.2-SNAPSHOT/reference/html/dsl.html#java-dsl。固定代码是这样的:

      @Bean
    public IntegrationFlow myFlow() {
        return IntegrationFlows.fromSupplier(integerSource()::getAndIncrement,
                                         c -> c.poller(Pollers.fixedRate(100)))
                    .channel("inputChannel")
                    .filter((Integer p) -> p > 0)
                    .transform(Object::toString)
                    .channel(MessageChannels.queue())
                    .get();
    }
    

    下周发布。

    【讨论】:

    • 太棒了。谢谢!
    【解决方案2】:

    您可以通过将from() 替换为fromSupplier() 来更改您的代码

    【讨论】:

    • 这不也是公认的答案所建议的吗?
    猜你喜欢
    • 2020-03-12
    • 2015-08-13
    • 2015-07-03
    • 1970-01-01
    • 2018-10-14
    • 1970-01-01
    • 1970-01-01
    • 2019-12-22
    • 2018-11-05
    相关资源
    最近更新 更多