对于最新的稳定版本,请使用 Spring Integration 6.4.3! |
Java 实现
提供的每个组件都使用o.s.i.jpa.core.JpaExecutor
类,而 API 的 API 类又使用o.s.i.jpa.core.JpaOperations
接口。JpaOperations
其作方式与典型的数据访问对象 (DAO) 类似,并提供 find、persist、executeUpdate 等方法。
对于大多数用例,默认实现 (o.s.i.jpa.core.DefaultJpaOperations
) 应该就足够了。
但是,如果需要自定义行为,您可以指定自己的实现。
要初始化JpaExecutor
,您必须使用接受以下之一的构造函数之一:
-
EntityManagerFactory
-
实体管理器
-
Jpa运营
以下示例演示如何初始化JpaExecutor
替换为entityManagerFactory
并在出站网关中使用它:
@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;
}