java.lang.NoClassDefFoundError: Could not initialize class com.amazonaws.secretsmanager.sql.AWSSecretsManagerMySQLDriver
ishanupadhyay opened this issue · 4 comments
Can anyone tell me the reason for this exception? The attempt to create a c3p0 pool connection is failing Below I have listed some of the log lines :
Exception in thread "C3P0PooledConnectionPoolManager[identityToken->2vub2da5vl71nm6ob8c8|52c5ff41, dataSourceName->sampleDB]-HelperThread-#2" java.lang.NoClassDefFoundError: Could not initialize class com.amazonaws.secretsmanager.sql.AWSSecretsManagerMySQLDriver
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:264)
at com.mchange.v2.c3p0.DriverManagerDataSource.ensureDriverLoaded(DriverManagerDataSource.java:143)
at com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:173)
at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:220)
at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:206)
at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.acquireResource(C3P0PooledConnectionPool.java:203)
at com.mchange.v2.resourcepool.BasicResourcePool.doAcquire(BasicResourcePool.java:1138)
at com.mchange.v2.resourcepool.BasicResourcePool.doAcquireAndDecrementPendingAcquiresWithinLockOnSuccess(BasicResourcePool.java:1125)
at com.mchange.v2.resourcepool.BasicResourcePool.access$700(BasicResourcePool.java:44)
at com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask.run(BasicResourcePool.java:1870)
at com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:696)
WARN | 2019-09-27 08:31:56,865 | C3P0PooledConnectionPoolManager[identityToken->2vub2da5vl71nm6ob8c8|52c5ff41, dataSourceName->sampleDB]-HelperThread-#0 | An Error forced the closing of Thread[C3P0PooledConnectionPoolManager[identityToken->2vub2da5vl71nm6ob8c8|52c5ff41, dataSourceName->sampleDB]-HelperThread-#0,5,main]. Will attempt to reconstruct, but this might mean that something bad is happening. |
Do you see any other errors? Could you check your c3p0 configuration - https://github.com/aws/aws-secretsmanager-jdbc
The thing that points me at that direction is "You are getting a java.lang.NoClassDefFoundError which does NOT mean that your class is missing (in that case you'd get a java.lang.ClassNotFoundException). The ClassLoader ran into an error while reading the class definition when trying to read the class." - from https://stackoverflow.com/questions/7325579/java-lang-noclassdeffounderror-could-not-initialize-class-xxx
I faced the same issue, however, it turned out because of version mismatch on aws-java-sdk-core
dependency.
When I put the same version for aws-java-sdk-core
and aws-java-sdk-secretsmanager
as it was specified in mvn dependency:tree
, things got resolved.
here was my debugging process:
- Wrote the main method on the same module where I was using these classes.
- Used
Class.forName
method and see what exactly is causing the issue. - It was failing so run
mvn dependency:tree
on the module and found the version mismatch - changed the version and WORKED!!!
This commit should resolve your issue: 221472a. Closing this Issue in favor of that commit.
I updated the same version for aws-java-sdk-core and aws-java-sdk-secretsmanager. things got resolved.
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-core</artifactId>
<version>1.12.715</version>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-secretsmanager</artifactId>
<version>1.12.715</version>
</dependency>