Spring integration Spring集成Jpa |使用MessagingGateway插入行

Spring integration Spring集成Jpa |使用MessagingGateway插入行,spring-integration,spring-integration-dsl,Spring Integration,Spring Integration Dsl,我创建了MessagingGateway和2个流。我没有弄错清单。当我创建person时,程序将休眠。 为什么?我怎样才能解决这个问题 MyService myService = context.getBean(MyService.class); System.out.println("persons = " + myService.getPersons()); System.out.println("person = " + myService.save

我创建了MessagingGateway和2个流。我没有弄错清单。当我创建person时,程序将休眠。 为什么?我怎样才能解决这个问题

MyService myService = context.getBean(MyService.class);
System.out.println("persons = " + myService.getPersons());
System.out.println("person = " + myService.save(new Person(0, "Alex")));

@MessagingGateway
public interface MyService {
    @Gateway(requestChannel = "flow1.input")
    @Payload("new java.util.Date()")
    Collection<Person> getPersons();

    @Gateway(requestChannel = "flow2.input")
    Person save(Person person);
}

@Bean
public IntegrationFlow flow1(EntityManagerFactory entityManagerFactory) {
    return f -> f
            .handle(Jpa.retrievingGateway(entityManagerFactory)
                    .jpaQuery("from Person")
            );
}

 @Bean
 public IntegrationFlow flow2(EntityManagerFactory entityManagerFactory) {
        return f -> f
                .handle(Jpa.outboundAdapter(entityManagerFactory)
                                .entityClass(Person.class)
                                .persistMode(PersistMode.PERSIST),
                        e -> e.transactional(true));
 }
MyService-MyService=context.getBean(MyService.class);
System.out.println(“persons=“+myService.getPersons());
System.out.println(“person=“+myService.save”(新的person(0,“Alex”)));
@消息网关
公共接口MyService{
@网关(requestChannel=“flow1.input”)
@有效负载(“new java.util.Date()”)
收款人();
@网关(requestChannel=“flow2.input”)
人救(人);
}
@豆子
公共集成流程1(EntityManagerFactory EntityManagerFactory){
返回f->f
.handle(Jpa.retrievingGateway(entityManagerFactory)
.jpaQuery(“来自个人”)
);
}
@豆子
公共集成流程2(EntityManagerFactory EntityManagerFactory){
返回f->f
.handle(Jpa.outboundAdapter(entityManagerFactory)
.entityClass(Person.class)
.persistMode(persistMode.PERSIST),
e->e.transactional(true));
}
因为出站通道适配器是一个
单向调用。这样的组件没有返回到网关调用的响应

见文件:和理论:

您应考虑更改网关方法合同<代码>人(人);<代码>到此

无效保存(个人)。当gateway为void(无效)时,意味着不需要回复,只要发送成功,您的程序将从此块退出。

因为出站通道适配器是一个单向调用。这样的组件没有返回到网关调用的响应

见文件:和理论:

您应考虑更改网关方法合同<代码>人(人);<代码>到此

无效保存(个人)。当gateway为
void
时,意味着不需要回复,只要发送成功,您的程序将从此块退出