Skip to content

Instantly share code, notes, and snippets.

@vavasthi
Created June 5, 2020 07:17
package in.springframework.blog.tutorials.configs;
import in.springframework.blog.tutorials.RequestContext;
import in.springframework.blog.tutorials.user.domain.User;
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 = "auditorAware")
public class EntityAuditConfig {
@Bean
public AuditorAware<Long> auditorAware() {
return new AuditorAware<Long>() {
@Override
public Optional<Long> getCurrentAuditor() {
return Optional.of(RequestContext.currentUser.get().getId());
}
};
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment