Spring 集成存储数据

Spring Integration storing data

我试图在 spring 集成中将日志信息存储在数据库中。下面的代码..

主要流程:

  @Bean
    public IntegrationFlow httpReq() {
            return IntegrationFlows.from(Http.inboundGateway("/foo")
                            .requestMapping(m -> m.methods(HttpMethod.POST)
                                   ).errorChannel("errorhandler.input")
                            .validator(new Validator()))
                    .transform(Transformers.objectToString())
                    .transform(new ObjectToXMlTransformer()).wireTap("subscribeChannel").bridge()
                    .get();
       
    }

存储流量

   @Bean
    public IntegrationFlow dbHandler(EntityManagerFactory entity) {
        return f -> f
                .transform(new AbstractPayloadTransformer<String,EntityClass>() {

                    @Override
                    protected EntityClass transformPayload(String payload) {
                        return new EntityClass(payload);

                    }
                })
                .handle(Jpa.outboundAdapter(entity)
                        .entityClass(EntityClass.class)
                        .persistMode(PersistMode.PERSIST), e -> e.transactional(true));
    }

这是我的频道:


  @Bean
    public SubscribableChannel subscribeChannel() {
        return MessageChannels.publishSubscribe("subscribeChannel")
                .get();
    }
 @Autowired
    private EntityManagerFactory entityManagerFactory;

   @Bean
    public IntegrationFlow subscribeFlow() {
        return IntegrationFlows.from("subscribeChannel")
                .bridge().handle(logger()).handle(dbHandler(entityManagerFactory)).get();
    }

我收到一条错误消息,指出发现了不明确的参数类型。这是错误

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'subscribeFlow' defined in class path resource [com/example/demo/configuration/IntegrationConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.integration.dsl.IntegrationFlow]: Factory method 'subscribeFlow' threw exception; nested exception is java.lang.IllegalArgumentException: Found ambiguous parameter type [class java.lang.Void] for method match: [public abstract void org.springframework.integration.dsl.IntegrationFlow.configure(org.springframework.integration.dsl.IntegrationFlowDefinition), public default org.springframework.messaging.MessageChannel org.springframework.integration.dsl.IntegrationFlow.getInputChannel()]

有什么解决方案吗?谢谢。

IntegrationFlow 不是要从 handle() 调用的服务。

我看不出 subscribeFlow 你的情况有什么原因。只需考虑像那样开始您的 dbHandler 流程 - IntegrationFlows.from("subscribeChannel").

如果你还坚持分那么多流,可以考虑使用to(IntegrationFlow)运算符:

/**
 * Finish this flow with delegation to other {@link IntegrationFlow} instance.
 * @param other the {@link IntegrationFlow} to compose with.
 * @return The {@link IntegrationFlow} instance based on this definition.
 * @since 5.5.4
 */
public IntegrationFlow to(IntegrationFlow other) {