All JaVers artifacts are published to Maven Central.
Spring Boot Starter
The easiest and strongly recommended way to start with Javers is adding one of our Spring Boot starters to your project dependencies.
If you are using MongoDB — take:
compile 'org.javers:javers-spring-boot-starter-mongo:7.7.0'
If you are using an SQL database:
compile 'org.javers:javers-spring-boot-starter-sql:7.7.0'
Please note that Javers 7.x is compatible with Spring Boot 3, so all Javers Spring integration modules require Java 17.
These starters provide default configuration and create the Javers instance as a Spring bean. You can start using Javers with almost no configuration.
Read more about Javers’ Spring Boot integration and Javers’ Spring integration.
Javers tutorial on baeldung.com
Eugen Baeldung has written an excellent tutorial about Javers — Using JaVers for Data Model Auditing in Spring Data
We recommend reading it in the first place.
Other Community Tutorials
This Getting Started written by Karsten Silz tells you how to get started with JaVers, how to query for one or more objects, how to query nested objects, and how to customize the versioning JSON.
Vanilla Javers
If you are not using Spring, add javers-core
to your project dependencies and (optionally) choose proper javers-repository
module.
javers-core
Gradle:
compile 'org.javers:javers-core:7.7.0'
Please note that Javers core and Javers persistence modules require Java 11.
If you’re going to use JaVers as an object diff tool, this is the only dependency you need.
javers-repository
If you are going to use JaVers as a data audit framework, choose the proper repository implementation. For example, if you’re using MongoDB add:
Gradle:
compile 'org.javers:javers-persistence-mongo:7.7.0'
If you are using an SQL database — add:
compile 'org.javers:javers-persistence-sql:7.7.0'
Create a JaVers instance
Use JaversBuilder
to create a JaVers instance:
import org.javers.core.Javers;
import org.javers.core.JaversBuilder;
//...
Javers javers = JaversBuilder.javers().build();
Now, the JaVers instance is up and ready, configured with reasonable defaults. Good enough to start.
Later on, you would probably need to refine the configuration and introduce some basic facts about your domain model to JaVers.
Object diff
Use the compare()
method to calculate a diff for two arbitrary complex domain objects:
Person tommyOld = new Person("tommy", "Tommy Smart");
Person tommyNew = new Person("tommy", "Tommy C. Smart");
Diff diff = javers.compare(tommyOld, tommyNew);
See more diff examples.
Object audit
Use the javers.commit()
method to audit changes done on your domain objects.
Javers saves subsequent versions of domain objects
as Snapshots
in JaversRepository
Person robert = new Person("bob", "Robert Martin");
javers.commit("user", robert);
See more audit examples.
Auto audit
In order to automatically audit objects saved to Spring Data repositories
use the @JaversSpringDataAuditable
annotation:
@JaversSpringDataAuditable
public interface PersonRepository extends CrudRepository<Person, String> {
}
Read more about the Auto audit aspects.