Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EnvironmentVaultConfiguration causes ClassNotFoundException if AWS SDK is not on the class path #786

Closed
grmblfrz opened this issue Apr 19, 2023 · 8 comments
Assignees
Labels
status: waiting-for-feedback We need additional information before we can continue type: regression A regression from a previous release

Comments

@grmblfrz
Copy link

After upgrading spring-vault-core from 3.0.1 to 3.0.2 my application no longer starts. It fails with java.lang.ClassNotFoundException: software.amazon.awssdk.auth.credentials.AwsCredentialsProvider. Is the dependency to com.amazonaws:aws-java-sdk-core mandatory even if not using AWS-IAM authentication?

@mp911de
Copy link
Member

mp911de commented Apr 20, 2023

This sounds like a bug. Can you attach the full stack trace so we get the detail where the exception is being thrown?

@mp911de mp911de added the type: bug A general bug label Apr 20, 2023
@grmblfrz
Copy link
Author

grmblfrz commented Apr 20, 2023

Please find attached the stacktrace (packages / source file names partially redacted):
stacktrace-redacted.txt

The problem only occurs with java -jar, when starting from the IDE (intellij idea) it works as expected. (needed to reload the maven project)
I will try to create a stripped down example.

@mp911de
Copy link
Member

mp911de commented Apr 20, 2023

java.lang.IllegalStateException: Failed to introspect Class [xx.xxx.xxxxxxx.backend.config.VaultPropertiesConfiguration] from ClassLoader [org.springframework.boot.loader.LaunchedURLClassLoader@6f496d9f]
	at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:483)
	at org.springframework.util.ReflectionUtils.doWithMethods(ReflectionUtils.java:360)
	at org.springframework.util.ReflectionUtils.getUniqueDeclaredMethods(ReflectionUtils.java:417)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.lambda$getTypeForFactoryMethod$1(AbstractAutowireCapableBeanFactory.java:748)
	at java.base/java.util.concurrent.ConcurrentHashMap.computeIfAbsent(ConcurrentHashMap.java:1740)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.getTypeForFactoryMethod(AbstractAutowireCapableBeanFactory.java:747)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.determineTargetType(AbstractAutowireCapableBeanFactory.java:680)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.predictBeanType(AbstractAutowireCapableBeanFactory.java:651)
	at org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:1632)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.doGetBeanNamesForType(DefaultListableBeanFactory.java:560)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanNamesForType(DefaultListableBeanFactory.java:532)
	at org.springframework.boot.autoconfigure.condition.OnBeanCondition.collectBeanNamesForType(OnBeanCondition.java:252)
	at org.springframework.boot.autoconfigure.condition.OnBeanCondition.getBeanNamesForType(OnBeanCondition.java:245)
	at org.springframework.boot.autoconfigure.condition.OnBeanCondition.getBeanNamesForType(OnBeanCondition.java:235)
	at org.springframework.boot.autoconfigure.condition.OnBeanCondition.getMatchingBeans(OnBeanCondition.java:183)
	at org.springframework.boot.autoconfigure.condition.OnBeanCondition.getMatchOutcome(OnBeanCondition.java:158)
	at org.springframework.boot.autoconfigure.condition.SpringBootCondition.matches(SpringBootCondition.java:47)
	... 25 common frames omitted
Caused by: java.lang.NoClassDefFoundError: software/amazon/awssdk/auth/credentials/AwsCredentialsProvider
	at java.base/java.lang.Class.getDeclaredMethods0(Native Method)
	at java.base/java.lang.Class.privateGetDeclaredMethods(Class.java:3402)
	at java.base/java.lang.Class.getDeclaredMethods(Class.java:2504)
	at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:465)
	... 41 common frames omitted
Caused by: java.lang.ClassNotFoundException: software.amazon.awssdk.auth.credentials.AwsCredentialsProvider
	at java.base/java.net.URLClassLoader.findClass(URLClassLoader.java:445)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:587)
	at org.springframework.boot.loader.LaunchedURLClassLoader.loadClass(LaunchedURLClassLoader.java:149)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:520)
	... 45 common frames omitted

This exception shows a failure originating from your class xx.xxx.xxxxxxx.backend.config.VaultPropertiesConfiguration. I suggest that you set a breakpoint in the ClassNotFoundException constructor and that you take a look with the debugger, where this comes from.

@mp911de mp911de added the status: waiting-for-feedback We need additional information before we can continue label Apr 20, 2023
@grmblfrz
Copy link
Author

Here is a small sample project:
vaultbugdemo.tar.gz
(with 3.0.2 it will crash with ClassNotFoundException, with 3.0.1 it will crash because of missing keystore, which is expected).

@mp911de
Copy link
Member

mp911de commented Apr 20, 2023

Thanks a lot, this makes things much easier.

@mp911de
Copy link
Member

mp911de commented Apr 20, 2023

Interestingly, the method body containing the AWS IAM code causes the failure. Moving the code into another class fixes the problem.

@mp911de mp911de changed the title java.lang.ClassNotFoundException after upgrade to 3.0.2 EnvironmentVaultConfiguration causes ClassNotFoundException if AWS SDK is not on the class path Apr 20, 2023
@mp911de mp911de self-assigned this Apr 20, 2023
@mp911de mp911de added type: regression A regression from a previous release and removed type: bug A general bug labels Apr 20, 2023
mp911de added a commit that referenced this issue Apr 20, 2023
Having the AWS IAM authentication code inside the method body creating AwsIamAuthentication causes class loading of the AwsCredentialsProvider class although the return type is ClientAuthentication.

With the code moved to an inner class, we mitigate that issue without actually knowing why the JVM attempts to load AwsIamAuthentication even the method isn't used.

Closes gh-786
@mp911de
Copy link
Member

mp911de commented Apr 20, 2023

That's fixed now. Care to test against the latest 3.0.3-SNAPSHOT?

@grmblfrz
Copy link
Author

I can confirm it works with 3.0.3-SNAPSHOT.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: waiting-for-feedback We need additional information before we can continue type: regression A regression from a previous release
Projects
None yet
Development

No branches or pull requests

2 participants