Class PersistentAuditEventRepository<T extends AuditEventRecordBase>
- Type Parameters:
T- 應用宣告的具體稽核 entity(繼承AuditEventRecordBase)
- All Implemented Interfaces:
org.springframework.boot.actuate.audit.AuditEventRepository
Actuator AuditEventRepository 的持久實作:把稽核事件寫入應用宣告的稽核表,取代消費端
可選的 in-memory ring buffer(易失)。領域無關的框架 opt-in 服務(見 ADR-013「界線修訂 R1」)。
本類保留原同步 JPA 契約;新版 audit feature 改用 AsyncAuditEventRepository 與 storage provider,
不會以本類作非同步寫入失敗時的 fallback。
依 ADR-017 泛型化於
AuditEventRecordBase:應用注入具體 repository 與 entity 工廠(如
new PersistentAuditEventRepository<>(auditEventJpaRepository, AuditEventRecord::new))。
應用以 @Bean 宣告本類別(plain class,對齊框架「app 接線」慣例)即:Spring Boot 的
AuditAutoConfiguration 退讓(不再用 InMemory 版)、AuditListener(收 AuditApplicationEvent
→ add(AuditEvent))與 /actuator/auditevents 端點皆改用本持久 sink——登入/授權/應用自訂(如代行)事件
全部落表可查。
寫入交易:無交易時建立可寫交易;唯讀交易時以 REQUIRES_NEW 獨立提交(外層 rollback
仍保留稽核);讀寫交易時加入外層,與業務資料一起 commit/rollback。
Spring 管理的 bean 會自動注入 transaction manager,既有兩參數接線不需修改;
多個 manager 或手動建構時可用三參數建構子明確指定與 repository 相同的 manager。
-
Constructor Summary
ConstructorsConstructorDescriptionPersistentAuditEventRepository(AuditEventJpaRepositoryBase<T> repository, Supplier<T> recordFactory) PersistentAuditEventRepository(AuditEventJpaRepositoryBase<T> repository, Supplier<T> recordFactory, org.springframework.transaction.PlatformTransactionManager transactionManager) -
Method Summary
-
Constructor Details
-
PersistentAuditEventRepository
public PersistentAuditEventRepository(AuditEventJpaRepositoryBase<T> repository, Supplier<T> recordFactory) - Parameters:
repository- 稽核事件 repository(應用宣告的具體型別)recordFactory- 稽核 entity 工廠(通常為具體類的建構子參考)
-
PersistentAuditEventRepository
public PersistentAuditEventRepository(AuditEventJpaRepositoryBase<T> repository, Supplier<T> recordFactory, org.springframework.transaction.PlatformTransactionManager transactionManager) - Parameters:
repository- 稽核事件 repositoryrecordFactory- 稽核 entity 工廠transactionManager- 與 repository 使用相同資料來源的 transaction manager
-
-
Method Details
-
add
public void add(org.springframework.boot.actuate.audit.AuditEvent event) - Specified by:
addin interfaceorg.springframework.boot.actuate.audit.AuditEventRepository
-
find
-