JPA 支援
Spring Integration 的 JPA (Java Persistence API) 模組提供了使用 JPA 執行各種資料庫操作的元件。
您需要將此依賴項包含到您的專案中
-
Maven
-
Gradle
<dependency>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-jpa</artifactId>
<version>6.3.5</version>
</dependency>
compile "org.springframework.integration:spring-integration-jpa:6.3.5"
JPA API 必須透過某些供應商特定的實作(例如 Hibernate ORM Framework)來包含。
提供了以下元件
這些元件可用於透過傳送和接收訊息來對目標資料庫執行 select
、create
、update
和 delete
操作。
JPA 輸入通道适配器可讓您使用 JPA 從資料庫輪詢和檢索 (select
) 資料,而 JPA 輸出通道适配器可讓您建立、更新和刪除實體。
您可以將輸出閘道器用於 JPA,以將實體持久化到資料庫,讓您可以繼續流程並執行下游的進一步元件。同樣地,您可以使用輸出閘道器從資料庫檢索實體。
例如,您可以使用輸出閘道器,該閘道器在其請求通道上接收具有 userId
作為酬載的 Message
,以查詢資料庫、檢索使用者實體,並將其向下傳遞以進行進一步處理。
由於意識到這些語義差異,Spring Integration 提供了兩個獨立的 JPA 輸出閘道器
-
檢索輸出閘道器
-
更新輸出閘道器