My Spring boot application has a multitenancy architecture and I'm using Javers to audit some data models.
The issue I'm facing is that Javers is not able to resolve the database based on my MongoDatabaseFactory implementation.
So far I've tried creating a Javers Configuration Bean which looks like this:
@Component
public class JaversMongoConfiguration {
@Autowired
CachedMongoClients cachedMongoClients;
@SneakyThrows
public Javers javers() {
MongoRepository javersMongoRepository =
new MongoRepository(cachedMongoClients.getMongoDatabaseForCurrentContext()); // Custom method to fetch the MongoDataBase based on current TenantContext
return JaversBuilder.javers()
.registerJaversRepository(javersMongoRepository)
.build();
}
}
This isn't working as during project build time, Javers instantiates the connection to the default database and dynamically doesn't switch to the tenant database as intended during run time.
Hence, all my audit logs are getting saved at the default database and not in tenant database.
Note: I'm using Javers Spring Boot Mongo starter and Javers Mongo Persistence Maven dependencies.