|
如需使用最新稳定版本,请使用 Spring Integration 7.0.4! |
Java 实现
提供的每个组件都使用了 o.s.i.jpa.core.JpaExecutor 类,该类反过来又实现了 o.s.i.jpa.core.JpaOperations 接口。
JpaOperations 像一个典型的数据访问对象(DAO),提供了 find、persist、executeUpdate 等方法。
对于大多数用例,默认实现(o.s.i.jpa.core.DefaultJpaOperations)应该已经足够。
然而,如果您需要自定义行为,可以指定您自己的实现。
要初始化 JpaExecutor,您必须使用接受以下之一的构造函数:
-
EntityManagerFactory
-
实体管理器
-
JpaOperations
下面的示例展示了如何使用 entityManagerFactory 初始化 JpaExecutor 并在出站网关中使用它:
@Bean
public JpaExecutor jpaExecutor() {
JpaExecutor executor = new JpaExecutor(this.entityManagerFactory);
executor.setJpaParameters(Collections.singletonList(new JpaParameter("firstName", null, "#this")));
executor.setUsePayloadAsParameterSource(true);
executor.setExpectSingleResult(true);
return executor;
}
@ServiceActivator(inputChannel = "getEntityChannel")
@Bean
public MessageHandler retrievingJpaGateway() {
JpaOutboundGateway gateway = new JpaOutboundGateway(jpaExecutor());
gateway.setGatewayType(OutboundGatewayType.RETRIEVING);
gateway.setOutputChannelName("resultsChannel");
return gateway;
}