aws / aws-secretsmanager-jdbc

The AWS Secrets Manager JDBC Library enables Java developers to easily connect to SQL databases using secrets stored in AWS Secrets Manager.
Apache License 2.0
159 stars 78 forks source link

Cannot resolve driver when loaded through a deployed war #26

Open devportilla opened 4 years ago

devportilla commented 4 years ago

Hello,

Im having issues while trying to use the connector on a regular spring-boot war deployed artifact on tomcat. So far i have seen the following:

Setup is: -Packaging type: war -Spring boot version: 1.3.5.RELEASE with the following starters: `

org.springframework.boot
 <artifactId>spring-boot-starter-jdbc</artifactId>

org.springframework.boot spring-boot-starter-web
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-actuator</artifactId>
    </dependency>`

-Aws secretsmanager jdbc version: 1.0.2

This is happening only when the artifact is a war file and not jar launched application, with the embedded tomcat instead of the external one.

Some guidance would be appreciated.

jefferyk commented 4 years ago

We had the similar experience when we set this up using a war and tomcat back in December. We just made sure there was a bean defined for the native jdbc driver, so that this error wouldn't occur. It wasn't used directly by our app, but it just needed to be called/defined, then the secret manager jdbc driver was able to find it and it worked successfully.

devportilla commented 4 years ago

Our current solution passed by setting the drivermanagerprotection to false on the jre memory leak prevention listener on our server.xml, but this doesnt seem too clean. For more information: https://tomcat.apache.org/tomcat-8.0-doc/config/listeners.html#JRE_Memory_Leak_Prevention_Listener_-_org.apache.catalina.core.JreMemoryLeakPreventionListener

gregory-viale-cbp commented 4 years ago

Hi, I have the same behaviour, the workaround to set driverManagerProtection to false worked for me as well.

raghusujju commented 4 years ago

I encountered this issue. Since, i have access to the code, I loaded the driver using class loader. The issue is gone. But this is still a workaround as it does not solve the real issue. I was using the postgresql driver. I have overwritten one of the posgresql classes similar to MySql classes.

indrayanivaze commented 4 years ago

I encountered this issue. Since, i have access to the code, I loaded the driver using class loader. The issue is gone. But this is still a workaround as it does not solve the real issue. I was using the postgresql driver. I have overwritten one of the posgresql classes similar to MySql classes.

I am getting exact same error. Can you please let me know how you used class loader to load postgresql driver ?

raghusujju commented 4 years ago

I overritten getDefaultDriverClass method inside AWSSecretsManagerPostgreSQLDriver.java ( as I was using postgres) to load the postgresql driver. JUst do a Class.forName("org.postgresql.Driver", false, this.getClass().getClassLoader());. AFter this the issue with driver load was gone.

llama95 commented 3 years ago

Can one elaborate exactly what the line is that needs to get inserted into the server.xml file? @gregory-viale-cbp @devportilla

would it look like this?? --> image or is that second line there just an example and it should instead look like this --> image

devportilla commented 3 years ago

@nehamallama Your server xml should have the following line : <Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" driverManagerProtection="false"/>

llama95 commented 3 years ago

@devportilla thanks it works. Can confirm that this issue is still active/this solution will temporarily mitigate the error. ~best

willtong1234 commented 3 years ago

Thank you for opening this issue - we are looking into it.

sthangavel commented 2 years ago

This issue will be resolved by adding driver jar in tomcat lib (in case of externalized tomcat).