如何使用 IntegrationFlowContext 作为流程配置的一部分?

how to use IntegrationFlowContext as part of process configuration?

作为我的 spring-boot 进程配置的一部分,我创建了多个非常相似的集成流程。
我当前的配置代码如下所示:

@Configuration
public class MyConfig {

    @Component
    public static class FlowFactory {
        public IntegrationFLow createFlow(String someValue) {
            return IntegrationFLows.from
            ...
            .get();
        }
    }

    @Bean
    public IntegrationFlow flow1(FlowFactory flowFactory) {
        return flowFactory.createFlow("1");
    } 
    @Bean
    public IntegrationFlow flow2(FlowFactory flowFactory) {
        return flowFactory.createFlow("2");
    } 
    @Bean
    public IntegrationFlow flow3(FlowFactory flowFactory) {
        return flowFactory.createFlow("3");
    } 

}

如何使用 IntegrationFlowContext 替换(在我的配置 class 中)那些带有注册循环的硬编码 bean?
也许像下面这样的东西?

@Configuration
public class MyConfig {

    @Component
    public static class FlowFactory {

        FlowFactory(IntegrationFlowContext flowContext) {
            for (String someValue : ImmutableList.of("1","2","3") {
                flowContext.registration(createFLow(someValue)).register();    
            }
        }

        private IntegrationFLow createFlow(String someValue) {
            return IntegrationFLows.from
            ...
            .get();
        }
    }

}

非常感谢您的宝贵时间和专业知识。
最好的问候

是的,你可以像那样使用 IntegrationFlowContext,但最好这样做 register() in the @PostConstructor: 有很多因素会影响我们如何注册bean,所以最好尽可能推迟流注册。

所以,在我看来是这样的:

@Component
public static class FlowFactory {
    private final IntegrationFlowContext flowContext;

    FlowFactory(IntegrationFlowContext flowContext) {
        this.flowContext = flowContext;
    }

    @PostConstruct
    public void init() {
        for (String someValue : ImmutableList.of("1","2","3") {
            this.flowContext.registration(createFLow(someValue)).register();    
        }
    }
}