HappyWeasel
Spring Boot - Audit 시 생성자, 편집자 이름 저장 본문
@Component
public class UserAuditorAware implements AuditorAware<String> {
@Override
public Optional<String> getCurrentAuditor() {
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
UserDetails userDetails = (UserDetails) authentication.getPrincipal();
return Optional.of(userDetails.getUsername());
}
}
@EnableJpaAuditing
@Configuration
public class AuditConfig {}
// Entity에
@CreatedBy
@CreatedDate
@LastModifiedBy
@LastModifiedDate
'Back-End > Spring' 카테고리의 다른 글
Spring Boot - Embedded Tomcat Container 추가 설정 (0) | 2021.01.26 |
---|---|
Spring - HttpServletResponse error 반환시 message가 비어서 올 때 (0) | 2021.01.20 |
JPA - CASCADE TYPE (0) | 2021.01.14 |
Spring Boot - JPA Infinite recursion (0) | 2021.01.12 |
Spring Boot - Exception 전역 처리 (0) | 2021.01.12 |
Comments