2

i am creating a maven multimoduled project one of the module for the hibernate entity only , issue is two services/api/maven_project are using same module , but one requires auditing but other dont , how i can keep my code intact (means ,without changing or removing @Audited annotation) , how to enable or disable envers auditing at run time or compile time, because after everything i have tried auditing is working for both api

i have tried

spring.jpa.properties.hibernate.integration.envers.enabled=false
spring.jpa.properties.hibernate.listeners.envers.autoRegister=false
spring.jpa.properties.hibernate.envers.autoRegisterListeners=false

hibernate.integration.envers.enabled=false
hibernate.listeners.envers.autoRegister=false
hibernate.envers.autoRegisterListeners=false
Atul Sharma
  • 41
  • 1
  • 6
  • can you exclude the Envers dependency for the module that doesn't require auditing? https://maven.apache.org/guides/introduction/introduction-to-optional-and-excludes-dependencies.html – Jens Schauder Jul 02 '19 at 09:07
  • yes Jens but in order to do that i have to change my all entity classes having @audited annotations and i want to keep them in order to use or enable them in future – Atul Sharma Jul 02 '19 at 09:13
  • If you set the dependencies to provided they will not be included in Spring Boot executable JAR and audting will not happen but the code compiles. – Simon Martinelli Jul 02 '19 at 09:46
  • The module containing the entities will keep the dependency. The annotations being present in the byte code is not a problem because annotations in byte code not found in the classpath get ignored. – Jens Schauder Jul 02 '19 at 10:27
  • thanks Simon and Jens it worked fine but is there any other options for enabling or disabling auditing by application.properties because thing will get messy after a while when another child module/service is introduced like A->B->C where A is Entity Module B is service (with auditing enabled or disabled) and C is another Service with B as dependency (and C have the capability to enable or Disable auditing of B), just somehow want to keep configuration centralized – Atul Sharma Jul 03 '19 at 06:07

1 Answers1

1

As per buræquete's answer

spring.jpa.properties.hibernate.integration.envers.enabled=false

Would do the job.

"Non-Spring Data JPA" Hibernate properties are configured through spring.jpa.properties.hibernate.*

Achala Dissanayake
  • 810
  • 3
  • 16
  • 33