From 93dfadee97ff28ba257edc7b5869122f1fece651 Mon Sep 17 00:00:00 2001 From: alvinmarshall Date: Sun, 28 Jul 2024 12:22:51 -0400 Subject: [PATCH] chore: add jpa AuditAwareImpl --- .../com/cheise_proj/auditing/AuditAwareImpl.java | 13 +++++++++++++ .../auditing/AuditingApplication.java | 2 -- .../java/com/cheise_proj/auditing/JpaConfig.java | 16 ++++++++++++++++ 3 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 src/main/java/com/cheise_proj/auditing/AuditAwareImpl.java create mode 100644 src/main/java/com/cheise_proj/auditing/JpaConfig.java diff --git a/src/main/java/com/cheise_proj/auditing/AuditAwareImpl.java b/src/main/java/com/cheise_proj/auditing/AuditAwareImpl.java new file mode 100644 index 0000000..5c24b49 --- /dev/null +++ b/src/main/java/com/cheise_proj/auditing/AuditAwareImpl.java @@ -0,0 +1,13 @@ +package com.cheise_proj.auditing; + +import org.springframework.data.domain.AuditorAware; + +import java.util.Optional; + +class AuditAwareImpl implements AuditorAware { + + @Override + public Optional getCurrentAuditor() { + return Optional.of("System"); + } +} \ No newline at end of file diff --git a/src/main/java/com/cheise_proj/auditing/AuditingApplication.java b/src/main/java/com/cheise_proj/auditing/AuditingApplication.java index 565dac8..3c46792 100644 --- a/src/main/java/com/cheise_proj/auditing/AuditingApplication.java +++ b/src/main/java/com/cheise_proj/auditing/AuditingApplication.java @@ -2,10 +2,8 @@ import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.data.jpa.repository.config.EnableJpaAuditing; @SpringBootApplication -@EnableJpaAuditing public class AuditingApplication { public static void main(String[] args) { diff --git a/src/main/java/com/cheise_proj/auditing/JpaConfig.java b/src/main/java/com/cheise_proj/auditing/JpaConfig.java new file mode 100644 index 0000000..ac832ec --- /dev/null +++ b/src/main/java/com/cheise_proj/auditing/JpaConfig.java @@ -0,0 +1,16 @@ +package com.cheise_proj.auditing; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.data.domain.AuditorAware; +import org.springframework.data.jpa.repository.config.EnableJpaAuditing; + +@Configuration +@EnableJpaAuditing(auditorAwareRef = "customAuditProvider") +class JpaConfig { + + @Bean + AuditorAware customAuditProvider() { + return new AuditAwareImpl(); + } +} \ No newline at end of file