top of page

SpringBoot IQ

  • Writer: Anand Nerurkar
    Anand Nerurkar
  • Jul 13
  • 1 min read

How to enable audit service of springboot


To leverage Audit Service ,pls follow below steps


  1. Enable entityListener for AuditEntityListener in in entity class and enable belowfiled

    @createdDate,@LastModifiedDate,@CreatedBy,@LastModifiedBy

  2. add componenet AuditAwareC implement AuditAware<String> to capture login details

  3. enable audit config for JPA with @EnablejpaAuditing


@Entity

@EntityListener("AuditEntityLister.class")

public class Item{


@createdDate

private LocalDateTime createdAt

@LastModifiedDate

private LocalDateTime updatedAt

@CreatedBy

private String createdBy

@LastModifiedBy

private String lastModifiedBy



}


how we can enable in nosql??

===

we can use same way as above , just instead of jpaaudit, we will use say mongodb @EnableMongoAuditing


do we need to include auditing fileds in every entity class??

-- not needed, we can define base entity ,include all those auditing fileds, at entiry level @MappedSuperclass

@EntityListener


then each entity will extend from this base entity. But lombok wont add eual and hashcode for these adited filed from super class. so we ned to ecpliclty tell lombok for that we need to add @equalandhascode(super=true)


how do u track entity modification across different user in micorservices architecture ? how can centralised audit service can be used??

====

above approach does not work as it is in microservices since it is distributed and isloated nature. normally microservies are per DB pattern as it is in individual serrvice following SRP.

so we make use of centralizedauditservcie in microservices.


say Item entity in icorservies may be modified by order,inventory and dispatch microservices-source system, what time , what chnages ,how will u identify it??





 
 
 

Recent Posts

See All
why springbatch job??

Spring Batch Job Spring Batch is designed exactly for batch workloads  like Pro*C migrations. ✅ Advantages: Chunk-oriented processing...

 
 
 
Pro*c Job to Spring Batch Job

Example1: 📌 Background Pro*C job  → Written in C with embedded SQL, often used for batch ETL-like jobs in Oracle. Spring Batch job  →...

 
 
 

Comments

Rated 0 out of 5 stars.
No ratings yet

Add a rating
  • Facebook
  • Twitter
  • LinkedIn

©2024 by AeeroTech. Proudly created with Wix.com

bottom of page