What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

To keep a historical record of object changes in a Spring Data MongoDB application, use JaVers: its Spring integration can capture repository saves and deletes and store object snapshots in MongoDB. Spring Data MongoDB auditing serves a different purpose: it adds created/modified metadata and current-user values to entities. You can use both when you need entity metadata and a change history.

How JaVers auditing works with Spring Data MongoDB

JaVers records object snapshots in its repository. When you read a commit, it recalculates the differences between the relevant snapshots; the documented MongoDB repository stores snapshots rather than persisted diff records. With the Spring integration, an aspect can intercept writes made through annotated Spring Data CRUD repositories.

This boundary matters: repository operations covered by the aspect are audited, but arbitrary database writes and changes made by external MongoDB clients do not pass through that Spring AOP interception point.

Add JaVers to a Spring Boot application

JaVers recommends its Spring Boot MongoDB starter for Boot applications. The official integration page shows version 7.11.8; treat that as the version in that documentation, not as an evergreen recommendation. Check the release-specific requirements before selecting a dependency.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
implementation 'org.javers:javers-spring-boot-starter-mongo:7.11.8'

The starter auto-configures a JaVers instance, its MongoDB repository connection, and audit aspect beans. For a non-Boot or manually configured Spring application, use the Mongo persistence implementation and register a JaVers Mongo repository with a MongoDB client and database. The JaVers repository configuration is documented at JaVers Repository Configuration.

Mark Spring Data repositories for auditing

Annotate the CRUD repository whose writes you want JaVers to audit:

@JaversSpringDataAuditable
public interface PersonRepository extends MongoRepository<Person, String> {
}

The JaVers Spring Data aspect advises save* and delete* methods on annotated CRUD repositories. The annotation therefore covers writes that go through the advised repository path, not every possible way of changing a MongoDB document. For suitable methods outside Spring Data repositories, the Spring integration also provides the method-level @JaversAuditable family. See JaVers Spring integration.

Configure meaningful commit authors

A JaVers commit can record an author. The Spring Boot starter uses a Spring Security author provider when it detects Spring Security; otherwise, its default mock provider returns unknown. If audit history must identify the person or service responsible for a change, configure an appropriate AuthorProvider rather than relying on that fallback. In a manual Spring setup, register the provider yourself. The starter behavior and configuration are described in JaVers Spring Boot integration.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Spring Data entity auditing has its own user-provider mechanism. For imperative applications, enable @EnableMongoAuditing and provide an AuditorAware bean when needed. For reactive applications, use @EnableReactiveMongoAuditing and ReactiveAuditorAware. Spring documents that the auditing infrastructure picks up such a bean from the application context to determine the current user for domain metadata: Auditing :: Spring Data MongoDB.

Choose how JaVers stores audit data

The JaVers MongoDB repository uses JSON serialization. Its documented collections are jv_head_id, which holds the last commit identifier, and jv_snapshots, which holds domain-object snapshots and commit metadata. Diffs are recalculated from snapshot pairs when commits are read; JaVers does not persist diff records as its repository representation.

By default, the starter connects JaVers to the application database. JaVers also documents configuring a separate database. That choice has an important consequence: according to JaVers, a separate JaVers database does not participate in the application-data transaction. Choose the storage layout with your isolation and operational ownership requirements in mind, and do not assume separate databases commit atomically with one another.

Check transaction and version requirements

The starter detects a MongoTransactionManager and creates a transactional JaVers instance linked to it when present; without one, it creates a non-transactional instance. Confirm that the target application has the transaction manager and MongoDB deployment configuration it actually requires. The cited documentation does not provide a complete compatibility matrix for every JaVers, Spring Boot, Spring Data MongoDB, Java, and MongoDB server combination.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

JaVers’ getting-started page states that JaVers 7.10 and later is compatible with Spring Boot 4, that its Spring integration modules require Java 17, and that core and persistence modules require Java 11. These are release-specific requirements, so verify them against the version you plan to use: JaVers Getting Started.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

JaVers versus Spring Data MongoDB auditing

Need Spring Data MongoDB auditing JaVers
Created/modified timestamps and current actor on an entity Yes. Enable auditing and provide an auditor provider as needed. Commit metadata can include an author; JaVers is primarily the object-history and diff mechanism.
Historical object snapshots and changes Not the feature described by Spring Data’s auditing documentation. Yes. JaVers stores snapshots and reconstructs diffs when commits are read.
Automatic capture point Entity auditing infrastructure. An AOP aspect around annotated repository writes, or explicit JaVers commits.
Storage Auditing metadata is part of entity auditing. A JaVers repository, configured with its MongoDB implementation and collections.

Use Spring Data auditing when the requirement is to know when an entity was created or modified and who the current auditor was. Use JaVers when the requirement is to inspect historical object states and changes. Enable both if the application needs both forms of information; configure their actor providers independently.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.