top of page

SpringBoot IQ

  • Writer: Anand Nerurkar
    Anand Nerurkar
  • 17 hours ago
  • 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
Tech ProgramManager Role

Tech Manager Intro === I’m Anand Nerurkar, currently working as a Senior Application Development Manager with over 21 years of IT...

 
 
 

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