sync source code with article

This commit is contained in:
amit.pandey
2020-04-12 00:01:36 +05:30
parent 8d5660f7a4
commit 53454088b0
20 changed files with 310 additions and 8 deletions

View File

@@ -0,0 +1,21 @@
package com.baeldung.hibernate.audit;
import java.util.Optional;
import org.springframework.data.domain.AuditorAware;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Component;
@Component("auditorProvider")
public class AuditorAwareImpl implements AuditorAware<String> {
@Override
public String getCurrentAuditor() {
return Optional.ofNullable(SecurityContextHolder.getContext())
.map(e -> e.getAuthentication())
.map(Authentication::getName)
.orElse(null);
}
}

View File

@@ -46,7 +46,7 @@ import com.google.common.base.Preconditions;
@Configuration
@EnableTransactionManagement
@EnableJpaRepositories(basePackages = { "com.baeldung.persistence" }, transactionManagerRef = "jpaTransactionManager")
@EnableJpaAuditing
@EnableJpaAuditing(auditorAwareRef = "auditorProvider")
@PropertySource({ "classpath:persistence-h2.properties" })
@ComponentScan({ "com.baeldung.persistence" })
public class PersistenceConfig {