From cac37f77c4f1f11ce18eb71b009dac8bca97196f Mon Sep 17 00:00:00 2001 From: Moary Chen Date: Mon, 25 Nov 2024 10:24:07 +0800 Subject: [PATCH] Registry Service Bus conn string provider only when conn string is not empty (#43076) --- sdk/spring/CHANGELOG.md | 2 ++ ...AzureServiceBusClientBuilderConfiguration.java | 5 +++-- ...ServiceBusClientBuilderConfigurationTests.java | 15 +++++++++++++++ 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/sdk/spring/CHANGELOG.md b/sdk/spring/CHANGELOG.md index 71544aa814772..c79ef3e9d2325 100644 --- a/sdk/spring/CHANGELOG.md +++ b/sdk/spring/CHANGELOG.md @@ -7,9 +7,11 @@ This section includes changes in `spring-cloud-azure-autoconfigure` module. #### Features Added - Support customize StaticConnectionStringProvider bean. [#42919](https://github.com/Azure/azure-sdk-for-java/pull/42919). +- Support customize StaticConnectionStringProvider bean. [#43076](https://github.com/Azure/azure-sdk-for-java/pull/43076). #### Bugs Fixed - Fix error: Event Hubs connection string is still used when it's configured to empty string. [#42880](https://github.com/Azure/azure-sdk-for-java/issues/42880). +- Fix error: Service Bus connection string is still used when it's configured to empty string. [#42880](https://github.com/Azure/azure-sdk-for-java/issues/42880). ### Spring Integration Azure Core This section includes changes in the `spring-integration-azure-core` module. diff --git a/sdk/spring/spring-cloud-azure-autoconfigure/src/main/java/com/azure/spring/cloud/autoconfigure/implementation/servicebus/AzureServiceBusClientBuilderConfiguration.java b/sdk/spring/spring-cloud-azure-autoconfigure/src/main/java/com/azure/spring/cloud/autoconfigure/implementation/servicebus/AzureServiceBusClientBuilderConfiguration.java index ca51da2817cd4..ebb532cac4dd4 100644 --- a/sdk/spring/spring-cloud-azure-autoconfigure/src/main/java/com/azure/spring/cloud/autoconfigure/implementation/servicebus/AzureServiceBusClientBuilderConfiguration.java +++ b/sdk/spring/spring-cloud-azure-autoconfigure/src/main/java/com/azure/spring/cloud/autoconfigure/implementation/servicebus/AzureServiceBusClientBuilderConfiguration.java @@ -14,8 +14,8 @@ import com.azure.spring.cloud.service.implementation.servicebus.factory.ServiceBusClientBuilderFactory; import org.springframework.beans.factory.ObjectProvider; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; +import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; -import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -51,7 +51,8 @@ ServiceBusClientBuilder serviceBusClientBuilder(ServiceBusClientBuilderFactory f } @Bean - @ConditionalOnProperty("spring.cloud.azure.servicebus.connection-string") + @ConditionalOnExpression("'${spring.cloud.azure.servicebus.connection-string:}' != ''") + @ConditionalOnMissingBean(value = AzureServiceType.ServiceBus.class, parameterizedContainer = ServiceConnectionStringProvider.class) StaticConnectionStringProvider staticServiceBusConnectionStringProvider() { return new StaticConnectionStringProvider<>(AzureServiceType.SERVICE_BUS, diff --git a/sdk/spring/spring-cloud-azure-autoconfigure/src/test/java/com/azure/spring/cloud/autoconfigure/implementation/servicebus/AzureServiceBusClientBuilderConfigurationTests.java b/sdk/spring/spring-cloud-azure-autoconfigure/src/test/java/com/azure/spring/cloud/autoconfigure/implementation/servicebus/AzureServiceBusClientBuilderConfigurationTests.java index e81ca568c79bf..071e24fcb7419 100644 --- a/sdk/spring/spring-cloud-azure-autoconfigure/src/test/java/com/azure/spring/cloud/autoconfigure/implementation/servicebus/AzureServiceBusClientBuilderConfigurationTests.java +++ b/sdk/spring/spring-cloud-azure-autoconfigure/src/test/java/com/azure/spring/cloud/autoconfigure/implementation/servicebus/AzureServiceBusClientBuilderConfigurationTests.java @@ -6,6 +6,8 @@ import com.azure.data.appconfiguration.ConfigurationClientBuilder; import com.azure.messaging.servicebus.ServiceBusClientBuilder; import com.azure.spring.cloud.autoconfigure.implementation.TestBuilderCustomizer; +import com.azure.spring.cloud.autoconfigure.implementation.context.properties.AzureGlobalProperties; +import com.azure.spring.cloud.autoconfigure.implementation.servicebus.properties.AzureServiceBusProperties; import com.azure.spring.cloud.core.provider.connectionstring.StaticConnectionStringProvider; import com.azure.spring.cloud.core.service.AzureServiceType; import com.azure.spring.cloud.service.implementation.servicebus.factory.ServiceBusClientBuilderFactory; @@ -77,6 +79,19 @@ void otherCustomizerShouldNotBeCalled() { }); } + @Test + void configureWithNamespaceAndEmptyConnectionString() { + this.contextRunner.withConfiguration(AutoConfigurations.of(AzureServiceBusAutoConfiguration.class)) + .withPropertyValues( + "spring.cloud.azure.servicebus.connection-string=", + "spring.cloud.azure.servicebus.namespace=test-servicebus-namespace") + .withBean(AzureGlobalProperties.class, AzureGlobalProperties::new) + .run(context -> { + assertThat(context).hasSingleBean(AzureServiceBusProperties.class); + assertThat(context).doesNotHaveBean(StaticConnectionStringProvider.class); + }); + } + private static class ServiceBusBuilderCustomizer extends TestBuilderCustomizer { }