Created
June 5, 2020 07:17
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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