Skip to content

Commit

Permalink
chore: add jpa AuditAwareImpl
Browse files Browse the repository at this point in the history
  • Loading branch information
alvinmarshall committed Jul 28, 2024
1 parent f878408 commit 93dfade
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
13 changes: 13 additions & 0 deletions src/main/java/com/cheise_proj/auditing/AuditAwareImpl.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.cheise_proj.auditing;

import org.springframework.data.domain.AuditorAware;

import java.util.Optional;

class AuditAwareImpl implements AuditorAware<String> {

@Override
public Optional<String> getCurrentAuditor() {
return Optional.of("System");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
16 changes: 16 additions & 0 deletions src/main/java/com/cheise_proj/auditing/JpaConfig.java
Original file line number Diff line number Diff line change
@@ -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<String> customAuditProvider() {
return new AuditAwareImpl();
}
}

0 comments on commit 93dfade

Please sign in to comment.