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

DefaultSecretKeyVaultClient incorrectly instantiated when config-client is disabled #795

Open
nickmcdowall opened this issue Jan 17, 2025 · 1 comment

Comments

@nickmcdowall
Copy link

nickmcdowall commented Jan 17, 2025

Expected Behavior

Simply adding a dependency on implementation("io.micronaut.azure:micronaut-azure-secret-manager")

and enabling eager initialisation of singleton beans at startup, i.e.

fun main(args: Array<String>) {
    build(*args)
        .eagerInitSingletons(true)
        .start()
}

we expect the app to continue to start up.

Actual Behaviour

We get a DependencyInjectionException when running the application in the local environment even though the config-client is disabled by default or explicitly, i.e.

micronaut:
  config-client:
    enabled: false

Error:

ERROR io.micronaut.runtime.Micronaut - Error starting Micronaut server: Bean definition [io.micronaut.azure.secretmanager.client.DefaultSecretKeyVaultClient] could not be loaded: Failed to inject value for parameter [client] of class: io.micronaut.azure.secretmanager.client.DefaultSecretKeyVaultClient

Message: No bean of type [com.azure.security.keyvault.secrets.SecretClient] exists. 
* [SecretClient] is disabled because:
 - Property [micronaut.config-client.enabled] with value [false] does not equal required value: true
Path Taken: new DefaultSecretKeyVaultClient(SecretClient client) --> new DefaultSecretKeyVaultClient([SecretClient client])
io.micronaut.context.exceptions.BeanInstantiationException: Bean definition [io.micronaut.azure.secretmanager.client.DefaultSecretKeyVaultClient] could not be loaded: Failed to inject value for parameter [client] of class: io.micronaut.azure.secretmanager.client.DefaultSecretKeyVaultClient

Upon inspection it looks like the following code might be the reason?:

Existing:

@Requires(classes = SecretClient.class)
public class DefaultSecretKeyVaultClient implements SecretKeyVaultClient {

Suggested change (look for beans not class on classpath):

@Requires(beans = SecretClient.class)
public class DefaultSecretKeyVaultClient implements SecretKeyVaultClient {

Steps To Reproduce

  1. Clone example project
  2. Run ./gradlew clean run

Environment Information

No response

Example Application

https://github.com/nickmcdowall/micronaut-sample-project

Version

4.7.4

@nickmcdowall
Copy link
Author

Worth highlighting that the issue appears only when the .eagerInitSingletons is enabled.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant