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

[BUG] springTokenCredentialProviderContextProvider bean is missing from the context #43147

Open
irina-bostan opened this issue Dec 2, 2024 · 2 comments
Assignees
Labels
azure-spring All azure-spring related issues Client This issue points to a problem in the data-plane of the library. customer-reported Issues that are reported by GitHub users external to the Azure organization. needs-team-attention Workflow: This issue needs attention from Azure service team or SDK team question The issue doesn't require a change to the product in order to be resolved. Most issues start as that

Comments

@irina-bostan
Copy link

Describe the bug
springTokenCredentialProviderContextProvider bean is missing from the context. When bean springCloudAzureGlobalProperties is registred, the condition dependsOn cannot be met. The code below:

@Override
        public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata,
                                            BeanDefinitionRegistry registry) {
            if (!registry.containsBeanDefinition(AZURE_GLOBAL_PROPERTY_BEAN_NAME)) {
                BeanDefinitionBuilder definitionBuilder = genericBeanDefinition(AzureGlobalProperties.class,
                    () -> Binder.get(this.environment)
                                .bindOrCreate(AzureGlobalProperties.PREFIX,
                                    AzureGlobalProperties.class));
                if (ClassUtils.isPresent(AZURE_AUTHENTICATION_TEMPLATE_CLASS_NAME, null)) {
                    definitionBuilder.addDependsOn(SPRING_TOKEN_CREDENTIAL_PROVIDER_CONTEXT_BEAN_NAME);
                }
                registry.registerBeanDefinition(AZURE_GLOBAL_PROPERTY_BEAN_NAME, definitionBuilder.getBeanDefinition());
            }
        }

    }

Exception or Stack Trace

{
  "level": "WARN",
  "correlationid": "|02796df5-cdce-42c8-91fc-4908209620d7.",
  "environment": "test",
  "instance": "instance_IS_UNDEFINED",
  "processId": "28092",
  "region": "Location_IS_UNDEFINED",
  "timestamp": "2024-12-02T15:10:19.700+0200",
  "slot": "main",
  "version": "1.0.0-SNAPSHOT",
  "type": "Business",
  "commit": "1234567",
  "application": "xxx: 1.0.0-SNAPSHOT",
  "logger": "o.s.c.a.AnnotationConfigApplicationContext",
  "thread": "main",
  "message": "Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'springCloudAzureGlobalProperties': 'springCloudAzureGlobalProperties' depends on missing bean 'springTokenCredentialProviderContextProvider'"
}
{
  "level": "ERROR",
  "correlationid": "|51fa975c-cf38-4ebe-b2be-8b9a99263912.",
  "environment": "test",
  "instance": "instance_IS_UNDEFINED",
  "processId": "12488",
  "region": "Location_IS_UNDEFINED",
  "timestamp": "2024-12-02T14:41:31.803+0200",
  "slot": "main",
  "version": "1.0.0-SNAPSHOT",
  "type": "Business",
  "commit": "1234567",
  "application": "xxx: 1.0.0-SNAPSHOT",
  "logger": "o.s.b.d.LoggingFailureAnalysisReporter",
  "thread": "main",
  "message": "\r\n\r\n***************************\r\nAPPLICATION FAILED TO START\r\n***************************\r\n\r\nDescription:\r\n\r\nA component required a bean named 'springTokenCredentialProviderContextProvider' that could not be found.\r\n\r\n\r\nAction:\r\n\r\nConsider defining a bean named 'springTokenCredentialProviderContextProvider' in your configuration.\r\n"
}

To Reproduce
Create a spring boot app, with eventhub binding and postgres passwordless connection (check application.properties configs)
If you run in debug mode, you'll see that the springTokenCredentialProviderContextProvider bean is configured in overall ApplicationContext, when the JDBC context is risen.

As EventHubsBinderConfiguration depends on AzureGlobalPropertiesAutoConfiguration, when registering the springCloudAzureGlobalProperties bean, the dependsOn condition will also run in this case.
When eventhub binder creates another ApplicationContext, the above context is not set as parent. Therefore, the springTokenCredentialProviderContextProvider bean is not available in that tiny context.
Check for: DefaultBinderFactory.initializeBinderContextSimple() -> useApplicationContextAsParent var

There're two separate application contexts and the springTokenCredentialProviderContextProvider bean is missing from the binder application context, thus the overall app cannot bootstrap.

Code Snippet
application.properties config:

spring:
  cloud:
    function:
      definition: consume;
    azure:
      eventhubs:
        enabled: true
        namespace: ${EVENTHUB_NAMESPACE:}
        event-hub-name: ${EVENTHUB_NAME:}
      credential:
        managed-identity-enabled: true
        client-id: ${APP_USER_ASSIGNED_IDENTITY_CLIENT_ID:}
    stream:
      eventhubs:
        bindings:
          consume-in-0:
            consumer:
              batch:
                max-size: 10
              checkpoint:
                mode: MANUAL
      poller:
        fixed-delay: 1000
        initial-delay: 0
      bindings:
        consume-in-0:
          binder: consumer-binder
          destination: ${EVENTHUB_NAME:}
          group: $Default
          consumer:
            batch-mode: true
      binders:
        consumer-binder:
          type: eventhubs
          default-candidate: false
          environment:
            spring:
              cloud:
                azure:
                  eventhubs:
                    namespace: ${EVENTHUB_NAMESPACE:}
                    event-hub-name: ${EVENTHUB_NAME:}
                    processor:
                      checkpoint-store:
                        account-name: ${STORAGE_ACCOUNT_NAME}
                        container-name: ${EVENTHUB_NAMESPACE:}
                        create-container-if-not-exists: true
  datasource:
    url: ${DB_URL}
    username: ${AZ_POSTGRESQL_AD_APP_USERNAME}
    azure:
      passwordless-enabled: true

EH consumption method:

@Bean
    public Consumer<Message<List<CloudEvent>>> consume(final EventProcessor eventProcessor) {
        return new EventHubMessageConsumer(eventProcessor);
    }

Expected behavior
Application context can bootstrap as usual.

Setup (please complete the following information):

  • Library/Libraries:

com.azure.spring:spring-cloud-azure-autoconfigure:5.18.0
com.azure.spring:spring-cloud-azure-starter-jdbc-postgresql:5.18.0
com.azure:azure-identity:1.14.2

  • Java version: 17
  • Frameworks: Spring Boot, Spring Cloud Azure
@github-actions github-actions bot added azure-spring All azure-spring related issues Client This issue points to a problem in the data-plane of the library. customer-reported Issues that are reported by GitHub users external to the Azure organization. needs-team-attention Workflow: This issue needs attention from Azure service team or SDK team question The issue doesn't require a change to the product in order to be resolved. Most issues start as that labels Dec 2, 2024
Copy link

github-actions bot commented Dec 2, 2024

Copy link

github-actions bot commented Dec 2, 2024

Thank you for your feedback. Tagging and routing to the team member best able to assist.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
azure-spring All azure-spring related issues Client This issue points to a problem in the data-plane of the library. customer-reported Issues that are reported by GitHub users external to the Azure organization. needs-team-attention Workflow: This issue needs attention from Azure service team or SDK team question The issue doesn't require a change to the product in order to be resolved. Most issues start as that
Projects
Status: Todo
Development

No branches or pull requests

2 participants