Audit : 감시, 감사하다.
Spring Data provides sophisticated support to transparently keep track of who created or changed an entity and when the change happened. To benefit from that functionality, you have to equip your entity classes with auditing metadata that can be defined either using annotations or by implementing an interface.
Spring Data JPA ships with an entity listener that can be used to trigger the capturing of auditing information. 중략...
You can also enable the AuditingEntityListener on a per-entity basis by using the @EntityListeners annotation, as follows:
Spring Data에서는 entity를 누가 생성/변경했는지, 해당 사건이 언제 발생하였는지를 추적하는 기능을 정교하게 제공하고있다. annotation을 사용하거나 인터페이스를 구현하는 것으로 해당 기능을 사용할 수 있다.
Spring Data JPA는 위의 기능을 수행하는데 사용될 entity listener를 제공한다. @EntityListeners annotations을 이용하여 entity 별로 AuditingEntityListener를 활성화할 수 있다.
밑은 해당 예시이다.
@Entity
@EntityListeners(AuditingEntityListener.class)
public class MyEntity {
}
As of Spring Data JPA 1.5, you can enable auditing by annotating a configuration class with the @EnableJpaAuditing annotation.
Spring Data JPA 1.5 부터 configuration class에 @EnableJpaAuditing annotation으로 auditing을 활성화 할 수 있다.
참고 : @SpringBootApplication 가 @configuration을 포함하고 있다.
(https://spring.io/guides/gs/spring-boot/ 의 Create an Application class 부분)
밑은 해당 예시이다.
@SpringBootApplication // main class of project. 이 annotation 위치부터 설정을 읽어 항상 프로젝트 최상단에 클래스가 위치해야한다.
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args); //내장 WAS 실행
}
}
위 내용은 아래 링크의 내용을 참고하였다.
https://docs.spring.io/spring-data/jpa/docs/2.5.2/reference/html/#auditing
Spring Data JPA - Reference Documentation
Example 109. Using @Transactional at query methods @Transactional(readOnly = true) interface UserRepository extends JpaRepository { List findByLastname(String lastname); @Modifying @Transactional @Query("delete from User u where u.active = false") void del
docs.spring.io
'Spring > 개념' 카테고리의 다른 글
IoC 제어의 역전 (0) | 2022.04.14 |
---|---|
gradle 개념 정리 (0) | 2022.01.03 |