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):
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
Describe the bug
springTokenCredentialProviderContextProviderbean is missing from the context. When beanspringCloudAzureGlobalPropertiesis registred, the conditiondependsOncannot be met. The code below:Exception or Stack Trace
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
springTokenCredentialProviderContextProviderbean is configured in overall ApplicationContext, when the JDBC context is risen.As
EventHubsBinderConfigurationdepends onAzureGlobalPropertiesAutoConfiguration, when registering thespringCloudAzureGlobalPropertiesbean, 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
springTokenCredentialProviderContextProviderbean is not available in that tiny context.Check for: DefaultBinderFactory.initializeBinderContextSimple() -> useApplicationContextAsParent var
There're two separate application contexts and the
springTokenCredentialProviderContextProviderbean is missing from the binder application context, thus the overall app cannot bootstrap.Code Snippet
application.properties config:
EH consumption method:
Expected behavior
Application context can bootstrap as usual.
Setup (please complete the following information):