Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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;
import java.util.Optional;
@Configuration
@EnableJpaAuditing(auditorAwareRef = "auditorProvider")
public class JpaAuditingConfiguration {
@Bean
public AuditorAware<String> auditorProvider() {
/*
if you are using spring security, you can get the currently logged username with following code segment.
SecurityContextHolder.getContext().getAuthentication().getName()
*/
return () -> Optional.ofNullable("chathuranga");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment