Skip to content

Instantly share code, notes, and snippets.

@chathurangat
Created June 1, 2018 10:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chathurangat/84eb7574f5303c0f59af992158a2c6bc to your computer and use it in GitHub Desktop.
Save chathurangat/84eb7574f5303c0f59af992158a2c6bc to your computer and use it in GitHub Desktop.
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