I have created a class in Spring boot to establish a global javers object that can be used by all classes. This is my code.
@Component
public class JaversInstance {
public static final Javers javers;
static
{
ConnectionProvider connectionProvider = new ConnectionProvider() {
@Override
public Connection getConnection() throws SQLException {
String url = "any_url";
Properties props = new Properties();
props.setProperty("user", "test");
props.setProperty("password", "test");
DriverManager.getConnection(url, props);
System.out.println("CONNECTION PROVIDER invoked");
return DriverManager.getConnection(url, props);
}
};
JaversSqlRepository sqlRepository = SqlRepositoryBuilder
.sqlRepository()
.withConnectionProvider(connectionProvider)
.withDialect(DialectName.MYSQL).build();
System.out.println("JAVERS instance creation");
javers = JaversBuilder.javers().registerJaversRepository(sqlRepository).build();
}
private JaversInstance() {
}
}
Output:
JAVERS instance creation
CONNECTION PROVIDER invoked
CONNECTION PROVIDER invoked
CONNECTION PROVIDER invoked
CONNECTION PROVIDER invoked
CONNECTION PROVIDER invoked
CONNECTION PROVIDER invoked
CONNECTION PROVIDER invoked
CONNECTION PROVIDER invoked
CONNECTION PROVIDER invoked
Can someone tell me what has happened here. Why the getConnection() is called so many times? Is this any kind of retry?