diff --git a/spring-cloud-consul-config/src/main/java/org/springframework/cloud/consul/config/ConfigWatch.java b/spring-cloud-consul-config/src/main/java/org/springframework/cloud/consul/config/ConfigWatch.java index d28636dc..db97c665 100644 --- a/spring-cloud-consul-config/src/main/java/org/springframework/cloud/consul/config/ConfigWatch.java +++ b/spring-cloud-consul-config/src/main/java/org/springframework/cloud/consul/config/ConfigWatch.java @@ -37,8 +37,8 @@ import org.springframework.context.SmartLifecycle; import org.springframework.core.style.ToStringCreator; import org.springframework.scheduling.TaskScheduler; import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler; +import org.springframework.util.ObjectUtils; import org.springframework.util.ReflectionUtils; -import org.springframework.util.StringUtils; import static org.springframework.cloud.consul.config.ConsulConfigProperties.Format.FILES; @@ -150,7 +150,7 @@ public class ConfigWatch implements ApplicationEventPublisherAware, SmartLifecyc // use the consul ACL token if found String aclToken = this.properties.getAclToken(); - if (StringUtils.isEmpty(aclToken)) { + if (ObjectUtils.isEmpty(aclToken)) { aclToken = null; } diff --git a/spring-cloud-consul-config/src/main/java/org/springframework/cloud/consul/config/ConsulConfigBootstrapConfiguration.java b/spring-cloud-consul-config/src/main/java/org/springframework/cloud/consul/config/ConsulConfigBootstrapConfiguration.java index 4f080e60..3a1c5f67 100644 --- a/spring-cloud-consul-config/src/main/java/org/springframework/cloud/consul/config/ConsulConfigBootstrapConfiguration.java +++ b/spring-cloud-consul-config/src/main/java/org/springframework/cloud/consul/config/ConsulConfigBootstrapConfiguration.java @@ -28,7 +28,7 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; import org.springframework.core.env.Environment; -import org.springframework.util.StringUtils; +import org.springframework.util.ObjectUtils; /** * @author Spencer Gibb @@ -51,7 +51,7 @@ public class ConsulConfigBootstrapConfiguration { @ConditionalOnMissingBean public ConsulConfigProperties consulConfigProperties(Environment env) { ConsulConfigProperties properties = new ConsulConfigProperties(); - if (StringUtils.isEmpty(properties.getName())) { + if (ObjectUtils.isEmpty(properties.getName())) { properties.setName(env.getProperty("spring.application.name", "application")); } return properties; diff --git a/spring-cloud-consul-config/src/main/java/org/springframework/cloud/consul/config/ConsulConfigDataLocationResolver.java b/spring-cloud-consul-config/src/main/java/org/springframework/cloud/consul/config/ConsulConfigDataLocationResolver.java index 081f028e..b85a3539 100644 --- a/spring-cloud-consul-config/src/main/java/org/springframework/cloud/consul/config/ConsulConfigDataLocationResolver.java +++ b/spring-cloud-consul-config/src/main/java/org/springframework/cloud/consul/config/ConsulConfigDataLocationResolver.java @@ -44,6 +44,7 @@ import org.springframework.cloud.consul.config.ConsulPropertySources.Context; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.lang.Nullable; import org.springframework.util.CollectionUtils; +import org.springframework.util.ObjectUtils; import org.springframework.util.StringUtils; import org.springframework.web.util.UriComponents; import org.springframework.web.util.UriComponentsBuilder; @@ -214,6 +215,7 @@ public class ConsulConfigDataLocationResolver implements ConfigDataLocationResol .bind(ConsulConfigProperties.PREFIX, Bindable.of(ConsulConfigProperties.class), bindHandler) .orElseGet(ConsulConfigProperties::new); + if (!StringUtils.hasText(properties.getName())) { properties.setName(binder.bind("spring.application.name", String.class).orElse("application")); } diff --git a/spring-cloud-consul-discovery/src/main/java/org/springframework/cloud/consul/serviceregistry/ConsulAutoRegistration.java b/spring-cloud-consul-discovery/src/main/java/org/springframework/cloud/consul/serviceregistry/ConsulAutoRegistration.java index 34ec74d9..95661bae 100644 --- a/spring-cloud-consul-discovery/src/main/java/org/springframework/cloud/consul/serviceregistry/ConsulAutoRegistration.java +++ b/spring-cloud-consul-discovery/src/main/java/org/springframework/cloud/consul/serviceregistry/ConsulAutoRegistration.java @@ -34,6 +34,7 @@ import org.springframework.context.ApplicationContext; import org.springframework.core.env.Environment; import org.springframework.util.Assert; import org.springframework.util.CollectionUtils; +import org.springframework.util.ObjectUtils; import org.springframework.util.StringUtils; /** @@ -197,10 +198,10 @@ public class ConsulAutoRegistration extends ConsulRegistration { } // add metadata from other properties. See createTags above. - if (!StringUtils.isEmpty(properties.getInstanceZone())) { + if (!ObjectUtils.isEmpty(properties.getInstanceZone())) { metadata.put(properties.getDefaultZoneMetadataName(), properties.getInstanceZone()); } - if (!StringUtils.isEmpty(properties.getInstanceGroup())) { + if (!ObjectUtils.isEmpty(properties.getInstanceGroup())) { metadata.put("group", properties.getInstanceGroup()); } diff --git a/spring-cloud-consul-discovery/src/main/java/org/springframework/cloud/consul/serviceregistry/ConsulAutoServiceRegistration.java b/spring-cloud-consul-discovery/src/main/java/org/springframework/cloud/consul/serviceregistry/ConsulAutoServiceRegistration.java index 457ebea3..b4deef5c 100644 --- a/spring-cloud-consul-discovery/src/main/java/org/springframework/cloud/consul/serviceregistry/ConsulAutoServiceRegistration.java +++ b/spring-cloud-consul-discovery/src/main/java/org/springframework/cloud/consul/serviceregistry/ConsulAutoServiceRegistration.java @@ -25,7 +25,7 @@ import org.springframework.cloud.client.serviceregistry.AutoServiceRegistrationP import org.springframework.cloud.consul.discovery.ConsulDiscoveryProperties; import org.springframework.retry.annotation.Retryable; import org.springframework.util.Assert; -import org.springframework.util.StringUtils; +import org.springframework.util.ObjectUtils; /** * @author Spencer Gibb @@ -119,7 +119,7 @@ public class ConsulAutoServiceRegistration extends AbstractAutoServiceRegistrati @SuppressWarnings("deprecation") protected String getAppName() { String appName = this.properties.getServiceName(); - return StringUtils.isEmpty(appName) ? super.getAppName() : appName; + return ObjectUtils.isEmpty(appName) ? super.getAppName() : appName; } @Override diff --git a/spring-cloud-consul-discovery/src/test/java/org/springframework/cloud/consul/serviceregistry/ConsulAutoServiceRegistrationCustomizedAgentAddressTests.java b/spring-cloud-consul-discovery/src/test/java/org/springframework/cloud/consul/serviceregistry/ConsulAutoServiceRegistrationCustomizedAgentAddressTests.java index d851e01f..75c880b9 100644 --- a/spring-cloud-consul-discovery/src/test/java/org/springframework/cloud/consul/serviceregistry/ConsulAutoServiceRegistrationCustomizedAgentAddressTests.java +++ b/spring-cloud-consul-discovery/src/test/java/org/springframework/cloud/consul/serviceregistry/ConsulAutoServiceRegistrationCustomizedAgentAddressTests.java @@ -34,7 +34,7 @@ import org.springframework.cloud.consul.test.ConsulTestcontainers; import org.springframework.context.annotation.Configuration; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringRunner; -import org.springframework.util.StringUtils; +import org.springframework.util.ObjectUtils; import static org.assertj.core.api.Assertions.assertThat; import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; @@ -64,7 +64,7 @@ public class ConsulAutoServiceRegistrationCustomizedAgentAddressTests { assertThat(service.getPort().intValue()).as("service port is 0").isNotEqualTo(0); assertThat(service.getId()).as("service id was wrong").isEqualTo("myTestService1-AA"); assertThat(service.getService()).as("service name was wrong").isEqualTo("myprefix-myTestService-AA"); - assertThat(StringUtils.isEmpty(service.getAddress())).as("service address must be empty").isTrue(); + assertThat(ObjectUtils.isEmpty(service.getAddress())).as("service address must be empty").isTrue(); } @Configuration(proxyBeanMethods = false) diff --git a/spring-cloud-consul-discovery/src/test/java/org/springframework/cloud/consul/serviceregistry/ConsulAutoServiceRegistrationCustomizedManagementServicePortTests.java b/spring-cloud-consul-discovery/src/test/java/org/springframework/cloud/consul/serviceregistry/ConsulAutoServiceRegistrationCustomizedManagementServicePortTests.java index 42d6ad08..a2bedac0 100644 --- a/spring-cloud-consul-discovery/src/test/java/org/springframework/cloud/consul/serviceregistry/ConsulAutoServiceRegistrationCustomizedManagementServicePortTests.java +++ b/spring-cloud-consul-discovery/src/test/java/org/springframework/cloud/consul/serviceregistry/ConsulAutoServiceRegistrationCustomizedManagementServicePortTests.java @@ -36,7 +36,7 @@ import org.springframework.cloud.consul.test.ConsulTestcontainers; import org.springframework.context.annotation.Configuration; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringRunner; -import org.springframework.util.StringUtils; +import org.springframework.util.ObjectUtils; import static org.assertj.core.api.Assertions.assertThat; import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; @@ -77,7 +77,7 @@ public class ConsulAutoServiceRegistrationCustomizedManagementServicePortTests { assertThat(service.getPort().intValue()).as("service port was 0").isNotEqualTo(0); assertThat(service.getId()).as("service id was wrong").isEqualTo("myTestService1-GG"); assertThat(service.getService()).as("service name was wrong").isEqualTo("myprefix-myTestService-GG"); - assertThat(StringUtils.isEmpty(service.getAddress())).as("service address must not be empty").isFalse(); + assertThat(ObjectUtils.isEmpty(service.getAddress())).as("service address must not be empty").isFalse(); assertThat(service.getAddress()).as("service address must equals hostname from discovery properties") .isEqualTo(this.discoveryProperties.getHostname()); @@ -89,7 +89,7 @@ public class ConsulAutoServiceRegistrationCustomizedManagementServicePortTests { .isEqualTo("myTestService1-GG-management"); assertThat(managementService.getService()).as("management service name was wrong") .isEqualTo("myprefix-myTestService-GG-management"); - assertThat(StringUtils.isEmpty(managementService.getAddress())) + assertThat(ObjectUtils.isEmpty(managementService.getAddress())) .as("management service address must not be empty").isFalse(); assertThat(managementService.getAddress()) .as("management service address must equals hostname from discovery properties") diff --git a/spring-cloud-consul-discovery/src/test/java/org/springframework/cloud/consul/serviceregistry/ConsulAutoServiceRegistrationManagementDisabledServiceTests.java b/spring-cloud-consul-discovery/src/test/java/org/springframework/cloud/consul/serviceregistry/ConsulAutoServiceRegistrationManagementDisabledServiceTests.java index e795b142..55574403 100644 --- a/spring-cloud-consul-discovery/src/test/java/org/springframework/cloud/consul/serviceregistry/ConsulAutoServiceRegistrationManagementDisabledServiceTests.java +++ b/spring-cloud-consul-discovery/src/test/java/org/springframework/cloud/consul/serviceregistry/ConsulAutoServiceRegistrationManagementDisabledServiceTests.java @@ -35,7 +35,7 @@ import org.springframework.cloud.consul.test.ConsulTestcontainers; import org.springframework.context.annotation.Configuration; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringRunner; -import org.springframework.util.StringUtils; +import org.springframework.util.ObjectUtils; import static org.assertj.core.api.Assertions.assertThat; import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; @@ -72,7 +72,7 @@ public class ConsulAutoServiceRegistrationManagementDisabledServiceTests { assertThat(service.getPort().intValue()).as("service port was 0").isNotEqualTo(0); assertThat(service.getId()).as("service id was wrong").isEqualTo("myTestService1-NM"); assertThat(service.getService()).as("service name was wrong").isEqualTo("myTestService-NM"); - assertThat(StringUtils.isEmpty(service.getAddress())).as("service address must not be empty").isFalse(); + assertThat(ObjectUtils.isEmpty(service.getAddress())).as("service address must not be empty").isFalse(); assertThat(service.getAddress()).as("service address must equals hostname from discovery properties") .isEqualTo(this.discoveryProperties.getHostname()); diff --git a/spring-cloud-consul-discovery/src/test/java/org/springframework/cloud/consul/serviceregistry/ConsulAutoServiceRegistrationManagementServiceTests.java b/spring-cloud-consul-discovery/src/test/java/org/springframework/cloud/consul/serviceregistry/ConsulAutoServiceRegistrationManagementServiceTests.java index eb2d9fe8..f0fc532c 100644 --- a/spring-cloud-consul-discovery/src/test/java/org/springframework/cloud/consul/serviceregistry/ConsulAutoServiceRegistrationManagementServiceTests.java +++ b/spring-cloud-consul-discovery/src/test/java/org/springframework/cloud/consul/serviceregistry/ConsulAutoServiceRegistrationManagementServiceTests.java @@ -35,7 +35,7 @@ import org.springframework.cloud.consul.test.ConsulTestcontainers; import org.springframework.context.annotation.Configuration; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringRunner; -import org.springframework.util.StringUtils; +import org.springframework.util.ObjectUtils; import static org.assertj.core.api.Assertions.assertThat; import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; @@ -68,7 +68,7 @@ public class ConsulAutoServiceRegistrationManagementServiceTests { assertThat(service.getPort().intValue()).as("service port was 0").isNotEqualTo(0); assertThat(service.getId()).as("service id was wrong").isEqualTo("myTestService-EE-0"); assertThat(service.getService()).as("service name was wrong").isEqualTo("myTestService-EE"); - assertThat(StringUtils.isEmpty(service.getAddress())).as("service address must not be empty").isFalse(); + assertThat(ObjectUtils.isEmpty(service.getAddress())).as("service address must not be empty").isFalse(); assertThat(service.getAddress()).as("service address must equals hostname from discovery properties") .isEqualTo(this.discoveryProperties.getHostname()); @@ -79,7 +79,7 @@ public class ConsulAutoServiceRegistrationManagementServiceTests { .isEqualTo("myTestService-EE-0-management"); assertThat(managementService.getService()).as("management service name was wrong") .isEqualTo("myTestService-EE-management"); - assertThat(StringUtils.isEmpty(managementService.getAddress())) + assertThat(ObjectUtils.isEmpty(managementService.getAddress())) .as("management service address must not be empty").isFalse(); assertThat(managementService.getAddress()) .as("management service address must equals hostname from discovery properties") diff --git a/spring-cloud-consul-discovery/src/test/java/org/springframework/cloud/consul/serviceregistry/ConsulAutoServiceRegistrationTests.java b/spring-cloud-consul-discovery/src/test/java/org/springframework/cloud/consul/serviceregistry/ConsulAutoServiceRegistrationTests.java index e2a3d61f..c24b1795 100644 --- a/spring-cloud-consul-discovery/src/test/java/org/springframework/cloud/consul/serviceregistry/ConsulAutoServiceRegistrationTests.java +++ b/spring-cloud-consul-discovery/src/test/java/org/springframework/cloud/consul/serviceregistry/ConsulAutoServiceRegistrationTests.java @@ -35,7 +35,7 @@ import org.springframework.cloud.consul.discovery.ConsulDiscoveryProperties; import org.springframework.cloud.consul.test.ConsulTestcontainers; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringRunner; -import org.springframework.util.StringUtils; +import org.springframework.util.ObjectUtils; import static org.assertj.core.api.Assertions.assertThat; import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; @@ -70,7 +70,7 @@ public class ConsulAutoServiceRegistrationTests { .isFalse(); assertThat(service.getId()).as("service id was wrong").isEqualTo(this.registration.getInstanceId()); assertThat(service.getService()).as("service name was wrong").isEqualTo("myTestService1-FF-something"); - assertThat(StringUtils.isEmpty(service.getAddress())).as("service address must not be empty").isFalse(); + assertThat(ObjectUtils.isEmpty(service.getAddress())).as("service address must not be empty").isFalse(); assertThat(service.getAddress()).as("service address must equals hostname from discovery properties") .isEqualTo(this.discoveryProperties.getHostname()); }