aws-secretsmanager-jdbc: Postgresql - Error - No Driver has been registered with name

I am using aws secrets manager to connect to postgresql db hosted on aws. When I try to run locally with groovy grails app, everything works seamlessly without any errors. But when I try to deploy war on tomcat 8, I see the error :

Caused by: java.lang.IllegalStateException: No Driver has been registered with name, org.postgresql.Driver. Please check your system properties or secretsmanager.properties for typos. Also ensure that the Driver registers itself.
	at com.amazonaws.secretsmanager.sql.AWSSecretsManagerDriver.getWrappedDriver(AWSSecretsManagerDriver.java:244)
	at com.amazonaws.secretsmanager.sql.AWSSecretsManagerDriver.acceptsURL(AWSSecretsManagerDriver.java:257)
	at com.zaxxer.hikari.util.DriverDataSource.<init>(DriverDataSource.java:83)
	at com.zaxxer.hikari.pool.PoolUtilities.initializeDataSource(PoolUtilities.java:114)

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 16 (2 by maintainers)

Most upvoted comments

Would be a very welcome addition. If done properly in the AWSSecretsManagerDriver class all other supported databases benefit as well. Best place IMO is in the getWrappedDriver() method:

protected void ensureRealDriverRegistered() {
	try {
	// Load the real driver through the same class loader as the wrapper
	Class<Driver> cls = (Class<Driver>) getClass().getClassLoader().loadClass(this.realDriverClass);
	DriverManager.registerDriver(cls.getDeclaredConstructor().newInstance()); 
} catch (Exception e) {
	e.printStackTrace();
}
}

public Driver getWrappedDriver() {
	ensureRealDriverRegistered();
     // existing code here 

What’s wrong in the current implementation is that getWrappedDriver() assumes the driver registers itself. This has two problems: a) not all drivers register themselves upon class loading b) if the connection is created e.g. in Tomcat, the real driver class is never loaded by the container (it only sees the wrapper driver class name) and hence there’s no chance the driver ever registers itself.