Why use Auditing?
Auditing provide informations that we can use for averiguate our data.
This specific method of auditoring provide the anotations @CreatedBy
, @CreatedDate
, @LastModifiedDate
and @LastModifiedBy
.
Attention: this informations is retrieved from the user authenticated with Spring Security.
Settings
Auditing only need spring-boot-data-jpa dependency. So, let's go to configs:
For this example I didn't add Spring Security, so I commented the code that takes the username of the authenticated user and added the String UNDEFINED!
In the line 24 I also handle /user
endpoints, which can be added without being authenticated!
Persisting data
Now, to test our auditing, persirt your object data with the method save of the spring-boot-data-jpa. See my code example!
User
Your can see the code of this project in GitHub