Search code examples
springjavers

Pass Spring datasource to Javers to Audit DTOs


In My Spring Boot application, I would like to audit DTOs instead of entities and move audit logic to common library which will have @EnableAudit annotation to audit DTO at method level. If I am using JaversBuilder.javers().build(); in common library I would not be able to commit data as it would not know anything of datasource.

I want to create Javers instance in my application and pass datasource to it and then pass Javers instances to common library to perform commit. Is there anyway in Spring boot application to create Javers instance and associat datasource to it which will be used at the time of commit ?


Solution

  • If you take javers-spring-boot-starter, you will get a Javers instance created as a Spring bean. It will be connected to your database and ready-to-use. See https://javers.org/documentation/spring-boot-integration/