From 35d41e4ae266c257596f54395b5b403f1ee705ab Mon Sep 17 00:00:00 2001 From: Stephane Nicoll Date: Tue, 6 Oct 2020 07:54:14 +0200 Subject: [PATCH] Remove code deprecated in Spring Boot 2.2 Closes gh-22034 --- ...CompositeHealthIndicatorConfiguration.java | 65 ---------- ...eReactiveHealthIndicatorConfiguration.java | 66 ---------- ...althAggregatorStatusAggregatorAdapter.java | 59 --------- ...egistryHealthIndicatorRegistryAdapter.java | 79 ------------ .../HealthEndpointAutoConfiguration.java | 16 +-- .../HealthIndicatorAutoConfiguration.java | 38 ------ .../health/HealthIndicatorProperties.java | 56 -------- ...cyHealthEndpointAdaptersConfiguration.java | 42 ------ ...lthEndpointCompatibilityConfiguration.java | 74 ----------- ...eactiveHealthIndicatorRegistryAdapter.java | 80 ------------ ...ggregatorStatusAggregatorAdapterTests.java | 52 -------- ...ryHealthIndicatorRegistryAdapterTests.java | 109 ---------------- .../HealthEndpointAutoConfigurationTests.java | 73 +---------- ...atorRegistryInjectionIntegrationTests.java | 85 ------------- ...veHealthIndicatorRegistryAdapterTests.java | 110 ---------------- .../health/AbstractHealthAggregator.java | 63 --------- .../health/CompositeHealthIndicator.java | 77 ----------- .../CompositeReactiveHealthIndicator.java | 89 ------------- .../DefaultHealthIndicatorRegistry.java | 92 -------------- ...efaultReactiveHealthIndicatorRegistry.java | 93 -------------- .../boot/actuate/health/HealthAggregator.java | 48 ------- .../health/HealthIndicatorNameFactory.java | 30 ----- .../HealthIndicatorReactiveAdapter.java | 9 +- .../health/HealthIndicatorRegistry.java | 70 ---------- .../HealthIndicatorRegistryFactory.java | 64 ---------- .../health/OrderedHealthAggregator.java | 108 ---------------- .../health/ReactiveHealthContributor.java | 1 - .../ReactiveHealthIndicatorRegistry.java | 70 ---------- ...eactiveHealthIndicatorRegistryFactory.java | 88 ------------- .../health/CompositeHealthIndicatorTests.java | 90 ------------- ...CompositeReactiveHealthIndicatorTests.java | 120 ------------------ .../DefaultHealthIndicatorRegistryTests.java | 103 --------------- ...tReactiveHealthIndicatorRegistryTests.java | 104 --------------- .../HealthIndicatorReactiveAdapterTests.java | 1 - .../health/OrderedHealthAggregatorTests.java | 87 ------------- .../ReactiveHealthContributorTests.java | 1 - ...veHealthIndicatorRegistryFactoryTests.java | 59 --------- .../ConfigurationBeanFactoryMetadata.java | 93 -------------- ...nableConfigurationPropertiesRegistrar.java | 2 - 39 files changed, 6 insertions(+), 2560 deletions(-) delete mode 100644 spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/health/CompositeHealthIndicatorConfiguration.java delete mode 100644 spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/health/CompositeReactiveHealthIndicatorConfiguration.java delete mode 100644 spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/health/HealthAggregatorStatusAggregatorAdapter.java delete mode 100644 spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/health/HealthContributorRegistryHealthIndicatorRegistryAdapter.java delete mode 100644 spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/health/HealthIndicatorAutoConfiguration.java delete mode 100644 spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/health/HealthIndicatorProperties.java delete mode 100644 spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/health/LegacyHealthEndpointAdaptersConfiguration.java delete mode 100644 spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/health/LegacyHealthEndpointCompatibilityConfiguration.java delete mode 100644 spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/health/ReactiveHealthContributorRegistryReactiveHealthIndicatorRegistryAdapter.java delete mode 100644 spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/health/HealthAggregatorStatusAggregatorAdapterTests.java delete mode 100644 spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/health/HealthContributorRegistryHealthIndicatorRegistryAdapterTests.java delete mode 100644 spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/health/HealthIndicatorRegistryInjectionIntegrationTests.java delete mode 100644 spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/health/ReactiveHealthContributorRegistryReactiveHealthIndicatorRegistryAdapterTests.java delete mode 100644 spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/AbstractHealthAggregator.java delete mode 100644 spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/CompositeHealthIndicator.java delete mode 100644 spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/CompositeReactiveHealthIndicator.java delete mode 100644 spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/DefaultHealthIndicatorRegistry.java delete mode 100644 spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/DefaultReactiveHealthIndicatorRegistry.java delete mode 100644 spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/HealthAggregator.java delete mode 100644 spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/HealthIndicatorNameFactory.java delete mode 100644 spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/HealthIndicatorRegistry.java delete mode 100644 spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/HealthIndicatorRegistryFactory.java delete mode 100644 spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/OrderedHealthAggregator.java delete mode 100644 spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/ReactiveHealthIndicatorRegistry.java delete mode 100644 spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/ReactiveHealthIndicatorRegistryFactory.java delete mode 100644 spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/CompositeHealthIndicatorTests.java delete mode 100644 spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/CompositeReactiveHealthIndicatorTests.java delete mode 100644 spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/DefaultHealthIndicatorRegistryTests.java delete mode 100644 spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/DefaultReactiveHealthIndicatorRegistryTests.java delete mode 100644 spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/OrderedHealthAggregatorTests.java delete mode 100644 spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/ReactiveHealthIndicatorRegistryFactoryTests.java delete mode 100644 spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/ConfigurationBeanFactoryMetadata.java diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/health/CompositeHealthIndicatorConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/health/CompositeHealthIndicatorConfiguration.java deleted file mode 100644 index 8bf2f7d7fbd..00000000000 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/health/CompositeHealthIndicatorConfiguration.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright 2012-2020 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.boot.actuate.autoconfigure.health; - -import java.util.Map; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.actuate.health.HealthIndicator; -import org.springframework.core.ResolvableType; - -/** - * Base class for configurations that can combine source beans using a - * {@link org.springframework.boot.actuate.health.CompositeHealthIndicator}. - * - * @param the health indicator type - * @param the bean source type - * @author Stephane Nicoll - * @since 2.0.0 - * @deprecated since 2.2.0 in favor of {@link CompositeHealthContributorConfiguration} - */ -@Deprecated -public abstract class CompositeHealthIndicatorConfiguration { - - @Autowired - private org.springframework.boot.actuate.health.HealthAggregator healthAggregator; - - protected HealthIndicator createHealthIndicator(Map beans) { - if (beans.size() == 1) { - return createHealthIndicator(beans.values().iterator().next()); - } - org.springframework.boot.actuate.health.HealthIndicatorRegistry registry = new org.springframework.boot.actuate.health.DefaultHealthIndicatorRegistry(); - beans.forEach((name, source) -> registry.register(name, createHealthIndicator(source))); - return new org.springframework.boot.actuate.health.CompositeHealthIndicator(this.healthAggregator, registry); - } - - @SuppressWarnings("unchecked") - protected H createHealthIndicator(S source) { - Class[] generics = ResolvableType.forClass(CompositeHealthIndicatorConfiguration.class, getClass()) - .resolveGenerics(); - Class indicatorClass = (Class) generics[0]; - Class sourceClass = (Class) generics[1]; - try { - return indicatorClass.getConstructor(sourceClass).newInstance(source); - } - catch (Exception ex) { - throw new IllegalStateException( - "Unable to create indicator " + indicatorClass + " for source " + sourceClass, ex); - } - } - -} diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/health/CompositeReactiveHealthIndicatorConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/health/CompositeReactiveHealthIndicatorConfiguration.java deleted file mode 100644 index ddee36d180e..00000000000 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/health/CompositeReactiveHealthIndicatorConfiguration.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright 2012-2020 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.boot.actuate.autoconfigure.health; - -import java.util.Map; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.actuate.health.ReactiveHealthIndicator; -import org.springframework.core.ResolvableType; - -/** - * Reactive variant of {@link CompositeHealthIndicatorConfiguration}. - * - * @param the health indicator type - * @param the bean source type - * @author Stephane Nicoll - * @since 2.0.0 - * @deprecated since 2.2.0 in favor of - * {@link CompositeReactiveHealthContributorConfiguration} - */ -@Deprecated -public abstract class CompositeReactiveHealthIndicatorConfiguration { - - @Autowired - private org.springframework.boot.actuate.health.HealthAggregator healthAggregator; - - protected ReactiveHealthIndicator createHealthIndicator(Map beans) { - if (beans.size() == 1) { - return createHealthIndicator(beans.values().iterator().next()); - } - org.springframework.boot.actuate.health.ReactiveHealthIndicatorRegistry registry = new org.springframework.boot.actuate.health.DefaultReactiveHealthIndicatorRegistry(); - beans.forEach((name, source) -> registry.register(name, createHealthIndicator(source))); - return new org.springframework.boot.actuate.health.CompositeReactiveHealthIndicator(this.healthAggregator, - registry); - } - - @SuppressWarnings("unchecked") - protected H createHealthIndicator(S source) { - Class[] generics = ResolvableType.forClass(CompositeReactiveHealthIndicatorConfiguration.class, getClass()) - .resolveGenerics(); - Class indicatorClass = (Class) generics[0]; - Class sourceClass = (Class) generics[1]; - try { - return indicatorClass.getConstructor(sourceClass).newInstance(source); - } - catch (Exception ex) { - throw new IllegalStateException( - "Unable to create indicator " + indicatorClass + " for source " + sourceClass, ex); - } - } - -} diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/health/HealthAggregatorStatusAggregatorAdapter.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/health/HealthAggregatorStatusAggregatorAdapter.java deleted file mode 100644 index c3867299cef..00000000000 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/health/HealthAggregatorStatusAggregatorAdapter.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright 2012-2020 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.boot.actuate.autoconfigure.health; - -import java.util.LinkedHashMap; -import java.util.Map; -import java.util.Set; - -import org.springframework.boot.actuate.health.Health; -import org.springframework.boot.actuate.health.Status; -import org.springframework.boot.actuate.health.StatusAggregator; - -/** - * Adapter class to convert a legacy - * {@link org.springframework.boot.actuate.health.HealthAggregator} to a - * {@link StatusAggregator}. - * - * @author Phillip Webb - */ -@SuppressWarnings("deprecation") -class HealthAggregatorStatusAggregatorAdapter implements StatusAggregator { - - private org.springframework.boot.actuate.health.HealthAggregator healthAggregator; - - HealthAggregatorStatusAggregatorAdapter(org.springframework.boot.actuate.health.HealthAggregator healthAggregator) { - this.healthAggregator = healthAggregator; - } - - @Override - public Status getAggregateStatus(Set statuses) { - int index = 0; - Map healths = new LinkedHashMap<>(); - for (Status status : statuses) { - index++; - healths.put("health" + index, asHealth(status)); - } - Health aggregate = this.healthAggregator.aggregate(healths); - return aggregate.getStatus(); - } - - private Health asHealth(Status status) { - return Health.status(status).build(); - } - -} diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/health/HealthContributorRegistryHealthIndicatorRegistryAdapter.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/health/HealthContributorRegistryHealthIndicatorRegistryAdapter.java deleted file mode 100644 index dafea4c44d9..00000000000 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/health/HealthContributorRegistryHealthIndicatorRegistryAdapter.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Copyright 2012-2020 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.boot.actuate.autoconfigure.health; - -import java.util.LinkedHashMap; -import java.util.Map; - -import org.springframework.boot.actuate.health.HealthContributor; -import org.springframework.boot.actuate.health.HealthContributorRegistry; -import org.springframework.boot.actuate.health.HealthIndicator; -import org.springframework.boot.actuate.health.NamedContributor; -import org.springframework.util.Assert; - -/** - * Adapter class to convert a {@link HealthContributorRegistry} to a legacy - * {@link org.springframework.boot.actuate.health.HealthIndicatorRegistry}. - * - * @author Phillip Webb - */ -@SuppressWarnings("deprecation") -class HealthContributorRegistryHealthIndicatorRegistryAdapter - implements org.springframework.boot.actuate.health.HealthIndicatorRegistry { - - private final HealthContributorRegistry contributorRegistry; - - HealthContributorRegistryHealthIndicatorRegistryAdapter(HealthContributorRegistry contributorRegistry) { - Assert.notNull(contributorRegistry, "ContributorRegistry must not be null"); - this.contributorRegistry = contributorRegistry; - } - - @Override - public void register(String name, HealthIndicator healthIndicator) { - this.contributorRegistry.registerContributor(name, healthIndicator); - } - - @Override - public HealthIndicator unregister(String name) { - HealthContributor contributor = this.contributorRegistry.unregisterContributor(name); - if (contributor instanceof HealthIndicator) { - return (HealthIndicator) contributor; - } - return null; - } - - @Override - public HealthIndicator get(String name) { - HealthContributor contributor = this.contributorRegistry.getContributor(name); - if (contributor instanceof HealthIndicator) { - return (HealthIndicator) contributor; - } - return null; - } - - @Override - public Map getAll() { - Map all = new LinkedHashMap<>(); - for (NamedContributor namedContributor : this.contributorRegistry) { - if (namedContributor.getContributor() instanceof HealthIndicator) { - all.put(namedContributor.getName(), (HealthIndicator) namedContributor.getContributor()); - } - } - return all; - } - -} diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/health/HealthEndpointAutoConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/health/HealthEndpointAutoConfiguration.java index d964c10c1e3..096a212ecfa 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/health/HealthEndpointAutoConfiguration.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/health/HealthEndpointAutoConfiguration.java @@ -20,7 +20,6 @@ import org.springframework.boot.actuate.autoconfigure.endpoint.condition.Conditi import org.springframework.boot.actuate.health.HealthEndpoint; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.context.properties.EnableConfigurationProperties; -import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; @@ -30,23 +29,14 @@ import org.springframework.context.annotation.Import; * @author Andy Wilkinson * @author Stephane Nicoll * @author Phillip Webb + * @author Scott Frederick * @since 2.0.0 */ @Configuration(proxyBeanMethods = false) @ConditionalOnAvailableEndpoint(endpoint = HealthEndpoint.class) -@EnableConfigurationProperties -@Import({ LegacyHealthEndpointAdaptersConfiguration.class, LegacyHealthEndpointCompatibilityConfiguration.class, - HealthEndpointConfiguration.class, ReactiveHealthEndpointConfiguration.class, +@EnableConfigurationProperties(HealthEndpointProperties.class) +@Import({ HealthEndpointConfiguration.class, ReactiveHealthEndpointConfiguration.class, HealthEndpointWebExtensionConfiguration.class, HealthEndpointReactiveWebExtensionConfiguration.class }) public class HealthEndpointAutoConfiguration { - @Bean - @SuppressWarnings("deprecation") - HealthEndpointProperties healthEndpointProperties(HealthIndicatorProperties healthIndicatorProperties) { - HealthEndpointProperties healthEndpointProperties = new HealthEndpointProperties(); - healthEndpointProperties.getStatus().getOrder().addAll(healthIndicatorProperties.getOrder()); - healthEndpointProperties.getStatus().getHttpMapping().putAll(healthIndicatorProperties.getHttpMapping()); - return healthEndpointProperties; - } - } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/health/HealthIndicatorAutoConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/health/HealthIndicatorAutoConfiguration.java deleted file mode 100644 index 330e625bba1..00000000000 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/health/HealthIndicatorAutoConfiguration.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright 2012-2020 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.boot.actuate.autoconfigure.health; - -import org.springframework.boot.actuate.health.HealthContributor; -import org.springframework.boot.autoconfigure.EnableAutoConfiguration; -import org.springframework.context.annotation.Configuration; - -/** - * {@link EnableAutoConfiguration Auto-configuration} for {@link HealthContributor health - * contributors}. - * - * @author Andy Wilkinson - * @author Stephane Nicoll - * @author Phillip Webb - * @author Vedran Pavic - * @since 2.0.0 - * @deprecated since 2.2.0 in favor of {@link HealthContributorAutoConfiguration} - */ -@Deprecated -@Configuration(proxyBeanMethods = false) -public class HealthIndicatorAutoConfiguration { - -} diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/health/HealthIndicatorProperties.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/health/HealthIndicatorProperties.java deleted file mode 100644 index 42afd82d5a7..00000000000 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/health/HealthIndicatorProperties.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright 2012-2020 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.boot.actuate.autoconfigure.health; - -import java.util.ArrayList; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; - -import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.boot.context.properties.DeprecatedConfigurationProperty; - -/** - * Configuration properties for some health properties. - * - * @author Christian Dupuis - * @since 2.0.0 - * @deprecated since 2.2.0 in favor of {@link HealthEndpointProperties} - */ -@Deprecated -@ConfigurationProperties(prefix = "management.health.status") -public class HealthIndicatorProperties { - - private List order = new ArrayList<>(); - - private final Map httpMapping = new LinkedHashMap<>(); - - @DeprecatedConfigurationProperty(replacement = "management.endpoint.health.status.order") - public List getOrder() { - return this.order; - } - - public void setOrder(List order) { - this.order = order; - } - - @DeprecatedConfigurationProperty(replacement = "management.endpoint.health.status.http-mapping") - public Map getHttpMapping() { - return this.httpMapping; - } - -} diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/health/LegacyHealthEndpointAdaptersConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/health/LegacyHealthEndpointAdaptersConfiguration.java deleted file mode 100644 index b04fa6d4e3f..00000000000 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/health/LegacyHealthEndpointAdaptersConfiguration.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright 2012-2020 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.boot.actuate.autoconfigure.health; - -import org.springframework.boot.actuate.health.StatusAggregator; -import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -/** - * Configuration to adapt legacy deprecated health endpoint classes and interfaces. - * - * @author Phillip Webb - * @author Scott Frederick - * @see HealthEndpointAutoConfiguration - */ -@Configuration(proxyBeanMethods = false) -@SuppressWarnings("deprecation") -class LegacyHealthEndpointAdaptersConfiguration { - - @Bean - @ConditionalOnBean(org.springframework.boot.actuate.health.HealthAggregator.class) - StatusAggregator healthAggregatorStatusAggregatorAdapter( - org.springframework.boot.actuate.health.HealthAggregator healthAggregator) { - return new HealthAggregatorStatusAggregatorAdapter(healthAggregator); - } - -} diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/health/LegacyHealthEndpointCompatibilityConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/health/LegacyHealthEndpointCompatibilityConfiguration.java deleted file mode 100644 index e06910737fb..00000000000 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/health/LegacyHealthEndpointCompatibilityConfiguration.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright 2012-2020 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.boot.actuate.autoconfigure.health; - -import reactor.core.publisher.Mono; - -import org.springframework.boot.actuate.health.HealthContributorRegistry; -import org.springframework.boot.actuate.health.ReactiveHealthContributorRegistry; -import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; -import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; -import org.springframework.boot.context.properties.EnableConfigurationProperties; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.util.CollectionUtils; - -/** - * Configuration to adapt legacy deprecated health endpoint classes and interfaces. - * - * @author Phillip Webb - * @author Scott Frederick - * @see HealthEndpointAutoConfiguration - */ -@Configuration(proxyBeanMethods = false) -@SuppressWarnings("deprecation") -@EnableConfigurationProperties(org.springframework.boot.actuate.autoconfigure.health.HealthIndicatorProperties.class) -class LegacyHealthEndpointCompatibilityConfiguration { - - @Bean - @ConditionalOnMissingBean - org.springframework.boot.actuate.health.HealthAggregator healthAggregator( - HealthIndicatorProperties healthIndicatorProperties) { - org.springframework.boot.actuate.health.OrderedHealthAggregator aggregator = new org.springframework.boot.actuate.health.OrderedHealthAggregator(); - if (!CollectionUtils.isEmpty(healthIndicatorProperties.getOrder())) { - aggregator.setStatusOrder(healthIndicatorProperties.getOrder()); - } - return aggregator; - } - - @Bean - @ConditionalOnMissingBean(org.springframework.boot.actuate.health.HealthIndicatorRegistry.class) - HealthContributorRegistryHealthIndicatorRegistryAdapter healthIndicatorRegistry( - HealthContributorRegistry healthContributorRegistry) { - return new HealthContributorRegistryHealthIndicatorRegistryAdapter(healthContributorRegistry); - } - - @Configuration(proxyBeanMethods = false) - @ConditionalOnClass(Mono.class) - static class LegacyReactiveHealthEndpointCompatibilityConfiguration { - - @Bean - @ConditionalOnMissingBean(org.springframework.boot.actuate.health.ReactiveHealthIndicatorRegistry.class) - ReactiveHealthContributorRegistryReactiveHealthIndicatorRegistryAdapter reactiveHealthIndicatorRegistry( - ReactiveHealthContributorRegistry reactiveHealthContributorRegistry) { - return new ReactiveHealthContributorRegistryReactiveHealthIndicatorRegistryAdapter( - reactiveHealthContributorRegistry); - } - - } - -} diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/health/ReactiveHealthContributorRegistryReactiveHealthIndicatorRegistryAdapter.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/health/ReactiveHealthContributorRegistryReactiveHealthIndicatorRegistryAdapter.java deleted file mode 100644 index 12f1713d1bb..00000000000 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/health/ReactiveHealthContributorRegistryReactiveHealthIndicatorRegistryAdapter.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Copyright 2012-2020 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.boot.actuate.autoconfigure.health; - -import java.util.LinkedHashMap; -import java.util.Map; - -import org.springframework.boot.actuate.health.NamedContributor; -import org.springframework.boot.actuate.health.ReactiveHealthContributor; -import org.springframework.boot.actuate.health.ReactiveHealthContributorRegistry; -import org.springframework.boot.actuate.health.ReactiveHealthIndicator; -import org.springframework.util.Assert; - -/** - * Adapter class to convert a {@link ReactiveHealthContributorRegistry} to a legacy - * {@link org.springframework.boot.actuate.health.ReactiveHealthIndicatorRegistry}. - * - * @author Phillip Webb - */ -@SuppressWarnings("deprecation") -class ReactiveHealthContributorRegistryReactiveHealthIndicatorRegistryAdapter - implements org.springframework.boot.actuate.health.ReactiveHealthIndicatorRegistry { - - private final ReactiveHealthContributorRegistry contributorRegistry; - - ReactiveHealthContributorRegistryReactiveHealthIndicatorRegistryAdapter( - ReactiveHealthContributorRegistry contributorRegistry) { - Assert.notNull(contributorRegistry, "ContributorRegistry must not be null"); - this.contributorRegistry = contributorRegistry; - } - - @Override - public void register(String name, ReactiveHealthIndicator healthIndicator) { - this.contributorRegistry.registerContributor(name, healthIndicator); - } - - @Override - public ReactiveHealthIndicator unregister(String name) { - ReactiveHealthContributor contributor = this.contributorRegistry.unregisterContributor(name); - if (contributor instanceof ReactiveHealthIndicator) { - return (ReactiveHealthIndicator) contributor; - } - return null; - } - - @Override - public ReactiveHealthIndicator get(String name) { - ReactiveHealthContributor contributor = this.contributorRegistry.getContributor(name); - if (contributor instanceof ReactiveHealthIndicator) { - return (ReactiveHealthIndicator) contributor; - } - return null; - } - - @Override - public Map getAll() { - Map all = new LinkedHashMap<>(); - for (NamedContributor namedContributor : this.contributorRegistry) { - if (namedContributor.getContributor() instanceof ReactiveHealthIndicator) { - all.put(namedContributor.getName(), (ReactiveHealthIndicator) namedContributor.getContributor()); - } - } - return all; - } - -} diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/health/HealthAggregatorStatusAggregatorAdapterTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/health/HealthAggregatorStatusAggregatorAdapterTests.java deleted file mode 100644 index c23aba63fed..00000000000 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/health/HealthAggregatorStatusAggregatorAdapterTests.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright 2012-2020 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.boot.actuate.autoconfigure.health; - -import java.util.List; - -import org.junit.jupiter.api.Test; - -import org.springframework.boot.actuate.health.Status; -import org.springframework.boot.actuate.health.StatusAggregator; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * Tests for {@link HealthAggregatorStatusAggregatorAdapter}. - * - * @author Phillip Webb - */ -@SuppressWarnings("deprecation") -class HealthAggregatorStatusAggregatorAdapterTests { - - @Test - void getAggregateStatusDelegateToHealthAggregator() { - StatusAggregator adapter = new HealthAggregatorStatusAggregatorAdapter(new TestHealthAggregator()); - Status status = adapter.getAggregateStatus(Status.UP, Status.DOWN); - assertThat(status.getCode()).isEqualTo("called2"); - } - - private static class TestHealthAggregator extends org.springframework.boot.actuate.health.AbstractHealthAggregator { - - @Override - protected Status aggregateStatus(List candidates) { - return new Status("called" + candidates.size()); - } - - } - -} diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/health/HealthContributorRegistryHealthIndicatorRegistryAdapterTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/health/HealthContributorRegistryHealthIndicatorRegistryAdapterTests.java deleted file mode 100644 index 0cc13271d42..00000000000 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/health/HealthContributorRegistryHealthIndicatorRegistryAdapterTests.java +++ /dev/null @@ -1,109 +0,0 @@ -/* - * Copyright 2012-2020 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.boot.actuate.autoconfigure.health; - -import java.util.Map; - -import org.junit.jupiter.api.Test; - -import org.springframework.boot.actuate.health.CompositeHealthContributor; -import org.springframework.boot.actuate.health.DefaultHealthContributorRegistry; -import org.springframework.boot.actuate.health.HealthContributorRegistry; -import org.springframework.boot.actuate.health.HealthIndicator; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; -import static org.assertj.core.api.Assertions.entry; -import static org.mockito.Mockito.mock; - -/** - * Tests for {@link HealthContributorRegistryHealthIndicatorRegistryAdapter}. - * - * @author Phillip Webb - */ -class HealthContributorRegistryHealthIndicatorRegistryAdapterTests { - - private HealthContributorRegistry contributorRegistry = new DefaultHealthContributorRegistry(); - - private HealthContributorRegistryHealthIndicatorRegistryAdapter adapter = new HealthContributorRegistryHealthIndicatorRegistryAdapter( - this.contributorRegistry); - - @Test - void createWhenContributorRegistryIsNullThrowsException() { - assertThatIllegalArgumentException() - .isThrownBy(() -> new HealthContributorRegistryHealthIndicatorRegistryAdapter(null)) - .withMessage("ContributorRegistry must not be null"); - } - - @Test - void registerDelegatesToContributorRegistry() { - HealthIndicator healthIndicator = mock(HealthIndicator.class); - this.adapter.register("test", healthIndicator); - assertThat(this.contributorRegistry.getContributor("test")).isSameAs(healthIndicator); - } - - @Test - void unregisterDelegatesToContributorRegistry() { - HealthIndicator healthIndicator = mock(HealthIndicator.class); - this.contributorRegistry.registerContributor("test", healthIndicator); - HealthIndicator unregistered = this.adapter.unregister("test"); - assertThat(unregistered).isSameAs(healthIndicator); - assertThat(this.contributorRegistry.getContributor("test")).isNull(); - } - - @Test - void unregisterWhenContributorRegistryResultIsNotHealthIndicatorReturnsNull() { - CompositeHealthContributor healthContributor = mock(CompositeHealthContributor.class); - this.contributorRegistry.registerContributor("test", healthContributor); - HealthIndicator unregistered = this.adapter.unregister("test"); - assertThat(unregistered).isNull(); - assertThat(this.contributorRegistry.getContributor("test")).isNull(); - } - - @Test - void getDelegatesToContributorRegistry() { - HealthIndicator healthIndicator = mock(HealthIndicator.class); - this.contributorRegistry.registerContributor("test", healthIndicator); - assertThat(this.adapter.get("test")).isSameAs(healthIndicator); - } - - @Test - void getWhenContributorRegistryResultIsNotHealthIndicatorReturnsNull() { - CompositeHealthContributor healthContributor = mock(CompositeHealthContributor.class); - this.contributorRegistry.registerContributor("test", healthContributor); - assertThat(this.adapter.get("test")).isNull(); - } - - @Test - void getAllDelegatesToContributorRegistry() { - HealthIndicator healthIndicator = mock(HealthIndicator.class); - this.contributorRegistry.registerContributor("test", healthIndicator); - Map all = this.adapter.getAll(); - assertThat(all).containsOnly(entry("test", healthIndicator)); - } - - @Test - void getAllWhenContributorRegistryContainsNonHealthIndicatorInstancesReturnsFilteredMap() { - CompositeHealthContributor healthContributor = mock(CompositeHealthContributor.class); - this.contributorRegistry.registerContributor("test1", healthContributor); - HealthIndicator healthIndicator = mock(HealthIndicator.class); - this.contributorRegistry.registerContributor("test2", healthIndicator); - Map all = this.adapter.getAll(); - assertThat(all).containsOnly(entry("test2", healthIndicator)); - } - -} diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/health/HealthEndpointAutoConfigurationTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/health/HealthEndpointAutoConfigurationTests.java index 7dad5d39558..07813f1d67f 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/health/HealthEndpointAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/health/HealthEndpointAutoConfigurationTests.java @@ -17,9 +17,6 @@ package org.springframework.boot.actuate.autoconfigure.health; import java.util.Collections; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; import org.junit.jupiter.api.Test; import reactor.core.publisher.Flux; @@ -65,7 +62,6 @@ import static org.mockito.Mockito.mock; * @author Stephane Nicoll * @author Scott Frederick */ -@SuppressWarnings("deprecation") class HealthEndpointAutoConfigurationTests { private final WebApplicationContextRunner contextRunner = new WebApplicationContextRunner() @@ -90,14 +86,6 @@ class HealthEndpointAutoConfigurationTests { }); } - @Test - void runWhenHasHealthAggregatorAdaptsToStatusAggregator() { - this.contextRunner.withUserConfiguration(HealthAggregatorConfiguration.class).run((context) -> { - StatusAggregator aggregator = context.getBean(StatusAggregator.class); - assertThat(aggregator.getAggregateStatus(Status.UP, Status.DOWN)).isEqualTo(Status.UNKNOWN); - }); - } - @Test void runCreatesStatusAggregatorFromProperties() { this.contextRunner.withPropertyValues("management.endpoint.health.status.order=up,down").run((context) -> { @@ -106,18 +94,10 @@ class HealthEndpointAutoConfigurationTests { }); } - @Test - void runWhenUsingDeprecatedPropertyCreatesStatusAggregatorFromProperties() { - this.contextRunner.withPropertyValues("management.health.status.order=up,down").run((context) -> { - StatusAggregator aggregator = context.getBean(StatusAggregator.class); - assertThat(aggregator.getAggregateStatus(Status.UP, Status.DOWN)).isEqualTo(Status.UP); - }); - } - @Test void runWhenHasStatusAggregatorBeanIgnoresProperties() { this.contextRunner.withUserConfiguration(StatusAggregatorConfiguration.class) - .withPropertyValues("management.health.status.order=up,down").run((context) -> { + .withPropertyValues("management.endpoint.health.status.order=up,down").run((context) -> { StatusAggregator aggregator = context.getBean(StatusAggregator.class); assertThat(aggregator.getAggregateStatus(Status.UP, Status.DOWN)).isEqualTo(Status.UNKNOWN); }); @@ -132,14 +112,6 @@ class HealthEndpointAutoConfigurationTests { }); } - @Test - void runUsingDeprecatedPropertyCreatesHttpCodeStatusMapperFromProperties() { - this.contextRunner.withPropertyValues("management.health.status.http-mapping.up=123").run((context) -> { - HttpCodeStatusMapper mapper = context.getBean(HttpCodeStatusMapper.class); - assertThat(mapper.getStatusCode(Status.UP)).isEqualTo(123); - }); - } - @Test void runWhenHasHttpCodeStatusMapperBeanIgnoresProperties() { this.contextRunner.withUserConfiguration(HttpCodeStatusMapperConfiguration.class) @@ -277,32 +249,6 @@ class HealthEndpointAutoConfigurationTests { }); } - @Test // gh-18354 - void runCreatesLegacyHealthAggregator() { - this.contextRunner.run((context) -> { - org.springframework.boot.actuate.health.HealthAggregator aggregator = context - .getBean(org.springframework.boot.actuate.health.HealthAggregator.class); - Map healths = new LinkedHashMap<>(); - healths.put("one", Health.up().build()); - healths.put("two", Health.down().build()); - Health result = aggregator.aggregate(healths); - assertThat(result.getStatus()).isEqualTo(Status.DOWN); - }); - } - - @Test - void runWhenReactorAvailableCreatesReactiveHealthIndicatorRegistryBean() { - this.contextRunner.run((context) -> assertThat(context) - .hasSingleBean(org.springframework.boot.actuate.health.ReactiveHealthIndicatorRegistry.class)); - } - - @Test // gh-18570 - void runWhenReactorUnavailableDoesNotCreateReactiveHealthIndicatorRegistryBean() { - this.contextRunner.withClassLoader(new FilteredClassLoader(Mono.class.getPackage().getName())) - .run((context) -> assertThat(context).doesNotHaveBean( - org.springframework.boot.actuate.health.ReactiveHealthIndicatorRegistry.class)); - } - @Test void runWhenHasHealthEndpointGroupsPostProcessorPerformsProcessing() { this.contextRunner.withPropertyValues("management.endpoint.health.group.ready.include=*").withUserConfiguration( @@ -333,23 +279,6 @@ class HealthEndpointAutoConfigurationTests { } - @Configuration(proxyBeanMethods = false) - static class HealthAggregatorConfiguration { - - @Bean - org.springframework.boot.actuate.health.HealthAggregator healthAggregator() { - return new org.springframework.boot.actuate.health.AbstractHealthAggregator() { - - @Override - protected Status aggregateStatus(List candidates) { - return Status.UNKNOWN; - } - - }; - } - - } - @Configuration(proxyBeanMethods = false) static class StatusAggregatorConfiguration { diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/health/HealthIndicatorRegistryInjectionIntegrationTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/health/HealthIndicatorRegistryInjectionIntegrationTests.java deleted file mode 100644 index bd222a2908f..00000000000 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/health/HealthIndicatorRegistryInjectionIntegrationTests.java +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Copyright 2012-2020 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.boot.actuate.autoconfigure.health; - -import io.micrometer.core.instrument.Gauge; -import io.micrometer.core.instrument.MeterRegistry; -import org.junit.jupiter.api.Test; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.actuate.autoconfigure.metrics.MeterRegistryAutoConfiguration; -import org.springframework.boot.actuate.autoconfigure.metrics.MetricsAutoConfiguration; -import org.springframework.boot.actuate.health.Status; -import org.springframework.boot.autoconfigure.ImportAutoConfiguration; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; -import org.springframework.context.annotation.Configuration; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * Integration test to ensure that the legacy - * {@link org.springframework.boot.actuate.health.HealthIndicatorRegistry} can still be - * injected. - * - * @author Phillip Webb - */ -@SuppressWarnings("deprecation") -@SpringBootTest(webEnvironment = WebEnvironment.NONE) -public class HealthIndicatorRegistryInjectionIntegrationTests { - - // gh-18194 - - @Test - void meterRegistryBeanHasBeenConfigured(@Autowired MeterRegistry meterRegistry) { - assertThat(meterRegistry).isNotNull(); - assertThat(meterRegistry.get("health").gauge()).isNotNull(); - } - - @Configuration - @ImportAutoConfiguration({ HealthEndpointAutoConfiguration.class, HealthContributorAutoConfiguration.class, - MeterRegistryAutoConfiguration.class, MetricsAutoConfiguration.class }) - static class Config { - - Config(org.springframework.boot.actuate.health.HealthAggregator healthAggregator, - org.springframework.boot.actuate.health.HealthIndicatorRegistry healthIndicatorRegistry, - MeterRegistry registry) { - org.springframework.boot.actuate.health.CompositeHealthIndicator healthIndicator = new org.springframework.boot.actuate.health.CompositeHealthIndicator( - healthAggregator, healthIndicatorRegistry); - Gauge.builder("health", healthIndicator, this::getGaugeValue) - .description("Spring boot health indicator. 3=UP, 2=OUT_OF_SERVICE, 1=DOWN, 0=UNKNOWN") - .strongReference(true).register(registry); - } - - private double getGaugeValue(org.springframework.boot.actuate.health.CompositeHealthIndicator health) { - Status status = health.health().getStatus(); - switch (status.getCode()) { - case "UP": - return 3; - case "OUT_OF_SERVICE": - return 2; - case "DOWN": - return 1; - case "UNKNOWN": - default: - return 0; - } - } - - } - -} diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/health/ReactiveHealthContributorRegistryReactiveHealthIndicatorRegistryAdapterTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/health/ReactiveHealthContributorRegistryReactiveHealthIndicatorRegistryAdapterTests.java deleted file mode 100644 index e40a93654f5..00000000000 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/health/ReactiveHealthContributorRegistryReactiveHealthIndicatorRegistryAdapterTests.java +++ /dev/null @@ -1,110 +0,0 @@ -/* - * Copyright 2012-2020 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.boot.actuate.autoconfigure.health; - -import java.util.Map; - -import org.junit.jupiter.api.Test; - -import org.springframework.boot.actuate.health.CompositeReactiveHealthContributor; -import org.springframework.boot.actuate.health.DefaultReactiveHealthContributorRegistry; -import org.springframework.boot.actuate.health.ReactiveHealthContributorRegistry; -import org.springframework.boot.actuate.health.ReactiveHealthIndicator; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; -import static org.assertj.core.api.Assertions.entry; -import static org.mockito.Mockito.mock; - -/** - * Test for - * {@link ReactiveHealthContributorRegistryReactiveHealthIndicatorRegistryAdapter}. - * - * @author Phillip Webb - */ -class ReactiveHealthContributorRegistryReactiveHealthIndicatorRegistryAdapterTests { - - private ReactiveHealthContributorRegistry contributorRegistry = new DefaultReactiveHealthContributorRegistry(); - - private ReactiveHealthContributorRegistryReactiveHealthIndicatorRegistryAdapter adapter = new ReactiveHealthContributorRegistryReactiveHealthIndicatorRegistryAdapter( - this.contributorRegistry); - - @Test - void createWhenContributorRegistryIsNullThrowsException() { - assertThatIllegalArgumentException() - .isThrownBy(() -> new ReactiveHealthContributorRegistryReactiveHealthIndicatorRegistryAdapter(null)) - .withMessage("ContributorRegistry must not be null"); - } - - @Test - void registerDelegatesToContributorRegistry() { - ReactiveHealthIndicator healthIndicator = mock(ReactiveHealthIndicator.class); - this.adapter.register("test", healthIndicator); - assertThat(this.contributorRegistry.getContributor("test")).isSameAs(healthIndicator); - } - - @Test - void unregisterDelegatesToContributorRegistry() { - ReactiveHealthIndicator healthIndicator = mock(ReactiveHealthIndicator.class); - this.contributorRegistry.registerContributor("test", healthIndicator); - ReactiveHealthIndicator unregistered = this.adapter.unregister("test"); - assertThat(unregistered).isSameAs(healthIndicator); - assertThat(this.contributorRegistry.getContributor("test")).isNull(); - } - - @Test - void unregisterWhenContributorRegistryResultIsNotHealthIndicatorReturnsNull() { - CompositeReactiveHealthContributor healthContributor = mock(CompositeReactiveHealthContributor.class); - this.contributorRegistry.registerContributor("test", healthContributor); - ReactiveHealthIndicator unregistered = this.adapter.unregister("test"); - assertThat(unregistered).isNull(); - assertThat(this.contributorRegistry.getContributor("test")).isNull(); - } - - @Test - void getDelegatesToContributorRegistry() { - ReactiveHealthIndicator healthIndicator = mock(ReactiveHealthIndicator.class); - this.contributorRegistry.registerContributor("test", healthIndicator); - assertThat(this.adapter.get("test")).isSameAs(healthIndicator); - } - - @Test - void getWhenContributorRegistryResultIsNotHealthIndicatorReturnsNull() { - CompositeReactiveHealthContributor healthContributor = mock(CompositeReactiveHealthContributor.class); - this.contributorRegistry.registerContributor("test", healthContributor); - assertThat(this.adapter.get("test")).isNull(); - } - - @Test - void getAllDelegatesToContributorRegistry() { - ReactiveHealthIndicator healthIndicator = mock(ReactiveHealthIndicator.class); - this.contributorRegistry.registerContributor("test", healthIndicator); - Map all = this.adapter.getAll(); - assertThat(all).containsOnly(entry("test", healthIndicator)); - } - - @Test - void getAllWhenContributorRegistryContainsNonHealthIndicatorInstancesReturnsFilteredMap() { - CompositeReactiveHealthContributor healthContributor = mock(CompositeReactiveHealthContributor.class); - this.contributorRegistry.registerContributor("test1", healthContributor); - ReactiveHealthIndicator healthIndicator = mock(ReactiveHealthIndicator.class); - this.contributorRegistry.registerContributor("test2", healthIndicator); - Map all = this.adapter.getAll(); - assertThat(all).containsOnly(entry("test2", healthIndicator)); - } - -} diff --git a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/AbstractHealthAggregator.java b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/AbstractHealthAggregator.java deleted file mode 100644 index 68e370cbddd..00000000000 --- a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/AbstractHealthAggregator.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright 2012-2020 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.boot.actuate.health; - -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; -import java.util.stream.Collectors; - -/** - * Base {@link HealthAggregator} implementation to allow subclasses to focus on - * aggregating the {@link Status} instances and not deal with contextual details etc. - * - * @author Christian Dupuis - * @author Vedran Pavic - * @since 1.1.0 - * @deprecated since 2.2.0 as {@link HealthAggregator} has been deprecated - */ -@Deprecated -public abstract class AbstractHealthAggregator implements HealthAggregator { - - @Override - public final Health aggregate(Map healths) { - List statusCandidates = healths.values().stream().map(Health::getStatus).collect(Collectors.toList()); - Status status = aggregateStatus(statusCandidates); - Map details = aggregateDetails(healths); - return new Health.Builder(status, details).build(); - } - - /** - * Return the single 'aggregate' status that should be used from the specified - * candidates. - * @param candidates the candidates - * @return a single status - */ - protected abstract Status aggregateStatus(List candidates); - - /** - * Return the map of 'aggregate' details that should be used from the specified - * healths. - * @param healths the health instances to aggregate - * @return a map of details - * @since 1.3.1 - */ - protected Map aggregateDetails(Map healths) { - return new LinkedHashMap<>(healths); - } - -} diff --git a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/CompositeHealthIndicator.java b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/CompositeHealthIndicator.java deleted file mode 100644 index 82c4c537db9..00000000000 --- a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/CompositeHealthIndicator.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright 2012-2020 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.boot.actuate.health; - -import java.util.LinkedHashMap; -import java.util.Map; - -/** - * {@link HealthIndicator} that returns health indications from all registered delegates. - * - * @author Tyler J. Frederick - * @author Phillip Webb - * @author Christian Dupuis - * @since 1.1.0 - * @deprecated since 2.2.0 in favor of a {@link CompositeHealthContributor} - */ -@Deprecated -public class CompositeHealthIndicator implements HealthIndicator { - - private final HealthIndicatorRegistry registry; - - private final HealthAggregator aggregator; - - /** - * Create a new {@link CompositeHealthIndicator} from the specified indicators. - * @param healthAggregator the health aggregator - * @param indicators a map of {@link HealthIndicator HealthIndicators} with the key - * being used as an indicator name. - */ - public CompositeHealthIndicator(HealthAggregator healthAggregator, Map indicators) { - this(healthAggregator, new DefaultHealthIndicatorRegistry(indicators)); - } - - /** - * Create a new {@link CompositeHealthIndicator} from the indicators in the given - * {@code registry}. - * @param healthAggregator the health aggregator - * @param registry the registry of {@link HealthIndicator HealthIndicators}. - */ - public CompositeHealthIndicator(HealthAggregator healthAggregator, HealthIndicatorRegistry registry) { - this.aggregator = healthAggregator; - this.registry = registry; - } - - /** - * Return the {@link HealthIndicatorRegistry} of this instance. - * @return the registry of nested {@link HealthIndicator health indicators} - * @since 2.1.0 - */ - public HealthIndicatorRegistry getRegistry() { - return this.registry; - } - - @Override - public Health health() { - Map healths = new LinkedHashMap<>(); - for (Map.Entry entry : this.registry.getAll().entrySet()) { - healths.put(entry.getKey(), entry.getValue().health()); - } - return this.aggregator.aggregate(healths); - } - -} diff --git a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/CompositeReactiveHealthIndicator.java b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/CompositeReactiveHealthIndicator.java deleted file mode 100644 index af027feb337..00000000000 --- a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/CompositeReactiveHealthIndicator.java +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Copyright 2012-2020 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.boot.actuate.health; - -import java.time.Duration; -import java.util.function.Function; - -import reactor.core.publisher.Flux; -import reactor.core.publisher.Mono; -import reactor.util.function.Tuple2; - -/** - * {@link ReactiveHealthIndicator} that returns health indications from all registered - * delegates. Provides an alternative {@link Health} for a delegate that reaches a - * configurable timeout. - * - * @author Stephane Nicoll - * @since 2.0.0 - * @deprecated since 2.2.0 in favor of a {@link CompositeReactiveHealthContributor} - */ -@Deprecated -public class CompositeReactiveHealthIndicator implements ReactiveHealthIndicator { - - private final ReactiveHealthIndicatorRegistry registry; - - private final HealthAggregator healthAggregator; - - private Long timeout; - - private Health timeoutHealth; - - private final Function, Mono> timeoutCompose; - - /** - * Create a new {@link CompositeReactiveHealthIndicator} from the indicators in the - * given {@code registry}. - * @param healthAggregator the health aggregator - * @param registry the registry of {@link ReactiveHealthIndicator HealthIndicators}. - */ - public CompositeReactiveHealthIndicator(HealthAggregator healthAggregator, - ReactiveHealthIndicatorRegistry registry) { - this.registry = registry; - this.healthAggregator = healthAggregator; - this.timeoutCompose = (mono) -> (this.timeout != null) - ? mono.timeout(Duration.ofMillis(this.timeout), Mono.just(this.timeoutHealth)) : mono; - } - - /** - * Specify an alternative timeout {@link Health} if a {@link HealthIndicator} failed - * to reply after specified {@code timeout}. - * @param timeout number of milliseconds to wait before using the - * {@code timeoutHealth} - * @param timeoutHealth the {@link Health} to use if an health indicator reached the - * {@code timeout} - * @return this instance - */ - public CompositeReactiveHealthIndicator timeoutStrategy(long timeout, Health timeoutHealth) { - this.timeout = timeout; - this.timeoutHealth = (timeoutHealth != null) ? timeoutHealth : Health.unknown().build(); - return this; - } - - ReactiveHealthIndicatorRegistry getRegistry() { - return this.registry; - } - - @Override - public Mono health() { - return Flux.fromIterable(this.registry.getAll().entrySet()) - .flatMap((entry) -> Mono.zip(Mono.just(entry.getKey()), - entry.getValue().health().transformDeferred(this.timeoutCompose))) - .collectMap(Tuple2::getT1, Tuple2::getT2).map(this.healthAggregator::aggregate); - } - -} diff --git a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/DefaultHealthIndicatorRegistry.java b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/DefaultHealthIndicatorRegistry.java deleted file mode 100644 index fbbceee5dd1..00000000000 --- a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/DefaultHealthIndicatorRegistry.java +++ /dev/null @@ -1,92 +0,0 @@ -/* - * Copyright 2012-2020 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.boot.actuate.health; - -import java.util.Collections; -import java.util.LinkedHashMap; -import java.util.Map; - -import org.springframework.util.Assert; - -/** - * Default implementation of {@link HealthIndicatorRegistry}. - * - * @author Vedran Pavic - * @author Stephane Nicoll - * @since 2.1.0 - * @deprecated since 2.2.0 in favor of {@link DefaultContributorRegistry} - */ -@Deprecated -public class DefaultHealthIndicatorRegistry implements HealthIndicatorRegistry { - - private final Object monitor = new Object(); - - private final Map healthIndicators; - - /** - * Create a new {@link DefaultHealthIndicatorRegistry}. - */ - public DefaultHealthIndicatorRegistry() { - this(new LinkedHashMap<>()); - } - - /** - * Create a new {@link DefaultHealthIndicatorRegistry} from the specified indicators. - * @param healthIndicators a map of {@link HealthIndicator}s with the key being used - * as an indicator name. - */ - public DefaultHealthIndicatorRegistry(Map healthIndicators) { - Assert.notNull(healthIndicators, "HealthIndicators must not be null"); - this.healthIndicators = new LinkedHashMap<>(healthIndicators); - } - - @Override - public void register(String name, HealthIndicator healthIndicator) { - Assert.notNull(healthIndicator, "HealthIndicator must not be null"); - Assert.notNull(name, "Name must not be null"); - synchronized (this.monitor) { - HealthIndicator existing = this.healthIndicators.putIfAbsent(name, healthIndicator); - if (existing != null) { - throw new IllegalStateException("HealthIndicator with name '" + name + "' already registered"); - } - } - } - - @Override - public HealthIndicator unregister(String name) { - Assert.notNull(name, "Name must not be null"); - synchronized (this.monitor) { - return this.healthIndicators.remove(name); - } - } - - @Override - public HealthIndicator get(String name) { - Assert.notNull(name, "Name must not be null"); - synchronized (this.monitor) { - return this.healthIndicators.get(name); - } - } - - @Override - public Map getAll() { - synchronized (this.monitor) { - return Collections.unmodifiableMap(new LinkedHashMap<>(this.healthIndicators)); - } - } - -} diff --git a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/DefaultReactiveHealthIndicatorRegistry.java b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/DefaultReactiveHealthIndicatorRegistry.java deleted file mode 100644 index 2d270b0d936..00000000000 --- a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/DefaultReactiveHealthIndicatorRegistry.java +++ /dev/null @@ -1,93 +0,0 @@ -/* - * Copyright 2012-2020 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.boot.actuate.health; - -import java.util.Collections; -import java.util.LinkedHashMap; -import java.util.Map; - -import org.springframework.util.Assert; - -/** - * Default implementation of {@link ReactiveHealthIndicatorRegistry}. - * - * @author Vedran Pavic - * @author Stephane Nicoll - * @since 2.1.0 - * @deprecated since 2.2.0 in favor of {@link DefaultContributorRegistry} - */ -@Deprecated -public class DefaultReactiveHealthIndicatorRegistry implements ReactiveHealthIndicatorRegistry { - - private final Object monitor = new Object(); - - private final Map healthIndicators; - - /** - * Create a new {@link DefaultReactiveHealthIndicatorRegistry}. - */ - public DefaultReactiveHealthIndicatorRegistry() { - this(new LinkedHashMap<>()); - } - - /** - * Create a new {@link DefaultReactiveHealthIndicatorRegistry} from the specified - * indicators. - * @param healthIndicators a map of {@link HealthIndicator}s with the key being used - * as an indicator name. - */ - public DefaultReactiveHealthIndicatorRegistry(Map healthIndicators) { - Assert.notNull(healthIndicators, "HealthIndicators must not be null"); - this.healthIndicators = new LinkedHashMap<>(healthIndicators); - } - - @Override - public void register(String name, ReactiveHealthIndicator healthIndicator) { - Assert.notNull(healthIndicator, "HealthIndicator must not be null"); - Assert.notNull(name, "Name must not be null"); - synchronized (this.monitor) { - ReactiveHealthIndicator existing = this.healthIndicators.putIfAbsent(name, healthIndicator); - if (existing != null) { - throw new IllegalStateException("HealthIndicator with name '" + name + "' already registered"); - } - } - } - - @Override - public ReactiveHealthIndicator unregister(String name) { - Assert.notNull(name, "Name must not be null"); - synchronized (this.monitor) { - return this.healthIndicators.remove(name); - } - } - - @Override - public ReactiveHealthIndicator get(String name) { - Assert.notNull(name, "Name must not be null"); - synchronized (this.monitor) { - return this.healthIndicators.get(name); - } - } - - @Override - public Map getAll() { - synchronized (this.monitor) { - return Collections.unmodifiableMap(new LinkedHashMap<>(this.healthIndicators)); - } - } - -} diff --git a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/HealthAggregator.java b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/HealthAggregator.java deleted file mode 100644 index 6d1ef43d0db..00000000000 --- a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/HealthAggregator.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright 2012-2020 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.boot.actuate.health; - -import java.util.Map; - -/** - * Strategy interface used to aggregate {@link Health} instances into a final one. - *

- * This is especially useful to combine subsystem states expressed through - * {@link Health#getStatus()} into one state for the entire system. The default - * implementation {@link OrderedHealthAggregator} sorts {@link Status} instances based on - * a priority list. - *

- * It is possible to add more complex {@link Status} types to the system. In that case - * either the {@link OrderedHealthAggregator} needs to be properly configured or users - * need to register a custom {@link HealthAggregator} as bean. - * - * @author Christian Dupuis - * @since 1.1.0 - * @deprecated since 2.2.0 in favor of {@link StatusAggregator} - */ -@FunctionalInterface -@Deprecated -public interface HealthAggregator { - - /** - * Aggregate several given {@link Health} instances into one. - * @param healths the health instances to aggregate - * @return the aggregated health - */ - Health aggregate(Map healths); - -} diff --git a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/HealthIndicatorNameFactory.java b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/HealthIndicatorNameFactory.java deleted file mode 100644 index 15014a2a785..00000000000 --- a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/HealthIndicatorNameFactory.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright 2012-2020 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.boot.actuate.health; - -/** - * Generate a sensible health indicator name based on its bean name. - * - * @author Stephane Nicoll - * @author Phillip Webb - * @since 2.0.0 - * @deprecated since 2.2.0 in favor of {@link HealthContributorNameFactory} - */ -@Deprecated -public class HealthIndicatorNameFactory extends HealthContributorNameFactory { - -} diff --git a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/HealthIndicatorReactiveAdapter.java b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/HealthIndicatorReactiveAdapter.java index 21ca6bb384e..fe68bb42ef7 100644 --- a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/HealthIndicatorReactiveAdapter.java +++ b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/HealthIndicatorReactiveAdapter.java @@ -26,17 +26,12 @@ import org.springframework.util.Assert; * safely invoked in a reactive environment. * * @author Stephane Nicoll - * @since 2.0.0 - * @deprecated since 2.2.0 in favor of - * {@link ReactiveHealthContributor#adapt(HealthContributor)} - * @see ReactiveHealthContributor#adapt(HealthContributor) */ -@Deprecated -public class HealthIndicatorReactiveAdapter implements ReactiveHealthIndicator { +class HealthIndicatorReactiveAdapter implements ReactiveHealthIndicator { private final HealthIndicator delegate; - public HealthIndicatorReactiveAdapter(HealthIndicator delegate) { + HealthIndicatorReactiveAdapter(HealthIndicator delegate) { Assert.notNull(delegate, "Delegate must not be null"); this.delegate = delegate; } diff --git a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/HealthIndicatorRegistry.java b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/HealthIndicatorRegistry.java deleted file mode 100644 index 86eb8d69527..00000000000 --- a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/HealthIndicatorRegistry.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright 2012-2020 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.boot.actuate.health; - -import java.util.Map; - -/** - * A mutable registry of {@link HealthIndicator HealthIndicators}. - *

- * Implementations must be thread-safe. - * - * @author Andy Wilkinson - * @author Vedran Pavic - * @author Stephane Nicoll - * @since 2.1.0 - * @see HealthEndpoint - * @deprecated since 2.2.0 in favor of a {@link HealthContributorRegistry} - */ -@Deprecated -public interface HealthIndicatorRegistry { - - /** - * Registers the given {@link HealthIndicator}, associating it with the given - * {@code name}. - * @param name the name of the indicator - * @param healthIndicator the indicator - * @throws IllegalStateException if the indicator cannot be registered with the given - * {@code name}. - */ - void register(String name, HealthIndicator healthIndicator); - - /** - * Unregisters the {@link HealthIndicator} previously registered with the given - * {@code name}. - * @param name the name of the indicator - * @return the unregistered indicator, or {@code null} if no indicator was found in - * the registry for the given {@code name}. - */ - HealthIndicator unregister(String name); - - /** - * Returns the {@link HealthIndicator} registered with the given {@code name}. - * @param name the name of the indicator - * @return the health indicator, or {@code null} if no indicator was registered with - * the given {@code name}. - */ - HealthIndicator get(String name); - - /** - * Returns a snapshot of the registered health indicators and their names. The - * contents of the map do not reflect subsequent changes to the registry. - * @return the snapshot of registered health indicators - */ - Map getAll(); - -} diff --git a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/HealthIndicatorRegistryFactory.java b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/HealthIndicatorRegistryFactory.java deleted file mode 100644 index 0cdef86d458..00000000000 --- a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/HealthIndicatorRegistryFactory.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright 2012-2020 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.boot.actuate.health; - -import java.util.Map; -import java.util.function.Function; - -import org.springframework.util.Assert; - -/** - * Factory to create a {@link HealthIndicatorRegistry}. - * - * @author Stephane Nicoll - * @since 2.1.0 - * @deprecated since 2.2.0 in favor of {@link DefaultHealthIndicatorRegistry} - */ -@Deprecated -public class HealthIndicatorRegistryFactory { - - private final Function healthIndicatorNameFactory; - - public HealthIndicatorRegistryFactory(Function healthIndicatorNameFactory) { - this.healthIndicatorNameFactory = healthIndicatorNameFactory; - } - - public HealthIndicatorRegistryFactory() { - this(new HealthIndicatorNameFactory()); - } - - /** - * Create a {@link HealthIndicatorRegistry} based on the specified health indicators. - * @param healthIndicators the {@link HealthIndicator} instances mapped by name - * @return a {@link HealthIndicator} that delegates to the specified - * {@code healthIndicators}. - */ - public HealthIndicatorRegistry createHealthIndicatorRegistry(Map healthIndicators) { - Assert.notNull(healthIndicators, "HealthIndicators must not be null"); - return initialize(new DefaultHealthIndicatorRegistry(), healthIndicators); - } - - protected T initialize(T registry, - Map healthIndicators) { - for (Map.Entry entry : healthIndicators.entrySet()) { - String name = this.healthIndicatorNameFactory.apply(entry.getKey()); - registry.register(name, entry.getValue()); - } - return registry; - } - -} diff --git a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/OrderedHealthAggregator.java b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/OrderedHealthAggregator.java deleted file mode 100644 index a3396f56b75..00000000000 --- a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/OrderedHealthAggregator.java +++ /dev/null @@ -1,108 +0,0 @@ -/* - * Copyright 2012-2020 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.boot.actuate.health; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Comparator; -import java.util.List; - -import org.springframework.util.Assert; - -/** - * Default {@link HealthAggregator} implementation that aggregates {@link Health} - * instances and determines the final system state based on a simple ordered list. - *

- * If a different order is required or a new {@link Status} type will be used, the order - * can be set by calling {@link #setStatusOrder(List)}. - * - * @author Christian Dupuis - * @since 1.1.0 - * @deprecated since 2.2.0 in favor of {@link SimpleStatusAggregator} - */ -@Deprecated -public class OrderedHealthAggregator extends AbstractHealthAggregator { - - private List statusOrder; - - /** - * Create a new {@link OrderedHealthAggregator} instance. - */ - public OrderedHealthAggregator() { - setStatusOrder(Status.DOWN, Status.OUT_OF_SERVICE, Status.UP, Status.UNKNOWN); - } - - /** - * Set the ordering of the status. - * @param statusOrder an ordered list of the status - */ - public void setStatusOrder(Status... statusOrder) { - String[] order = new String[statusOrder.length]; - for (int i = 0; i < statusOrder.length; i++) { - order[i] = statusOrder[i].getCode(); - } - setStatusOrder(Arrays.asList(order)); - } - - /** - * Set the ordering of the status. - * @param statusOrder an ordered list of the status codes - */ - public void setStatusOrder(List statusOrder) { - Assert.notNull(statusOrder, "StatusOrder must not be null"); - this.statusOrder = statusOrder; - } - - @Override - protected Status aggregateStatus(List candidates) { - // Only sort those status instances that we know about - List filteredCandidates = new ArrayList<>(); - for (Status candidate : candidates) { - if (this.statusOrder.contains(candidate.getCode())) { - filteredCandidates.add(candidate); - } - } - // If no status is given return UNKNOWN - if (filteredCandidates.isEmpty()) { - return Status.UNKNOWN; - } - // Sort given Status instances by configured order - filteredCandidates.sort(new StatusComparator(this.statusOrder)); - return filteredCandidates.get(0); - } - - /** - * {@link Comparator} used to order {@link Status}. - */ - private static class StatusComparator implements Comparator { - - private final List statusOrder; - - StatusComparator(List statusOrder) { - this.statusOrder = statusOrder; - } - - @Override - public int compare(Status s1, Status s2) { - int i1 = this.statusOrder.indexOf(s1.getCode()); - int i2 = this.statusOrder.indexOf(s2.getCode()); - return (i1 < i2) ? -1 : (i1 != i2) ? 1 : s1.getCode().compareTo(s2.getCode()); - } - - } - -} diff --git a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/ReactiveHealthContributor.java b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/ReactiveHealthContributor.java index 28677b4e8c1..89b4c3a148e 100644 --- a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/ReactiveHealthContributor.java +++ b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/ReactiveHealthContributor.java @@ -31,7 +31,6 @@ import org.springframework.util.Assert; */ public interface ReactiveHealthContributor { - @SuppressWarnings("deprecation") static ReactiveHealthContributor adapt(HealthContributor healthContributor) { Assert.notNull(healthContributor, "HealthContributor must not be null"); if (healthContributor instanceof HealthIndicator) { diff --git a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/ReactiveHealthIndicatorRegistry.java b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/ReactiveHealthIndicatorRegistry.java deleted file mode 100644 index 84d92b97e2d..00000000000 --- a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/ReactiveHealthIndicatorRegistry.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright 2012-2020 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.boot.actuate.health; - -import java.util.Map; - -/** - * A registry of {@link ReactiveHealthIndicator ReactiveHealthIndicators}. - *

- * Implementations must be thread-safe. - * - * @author Andy Wilkinson - * @author Vedran Pavic - * @author Stephane Nicoll - * @since 2.1.0 - * @see HealthIndicatorRegistry - * @deprecated since 2.2.0 in favor of a {@link ReactiveHealthContributorRegistry} - */ -@Deprecated -public interface ReactiveHealthIndicatorRegistry { - - /** - * Registers the given {@link ReactiveHealthIndicator}, associating it with the given - * {@code name}. - * @param name the name of the indicator - * @param healthIndicator the indicator - * @throws IllegalStateException if an indicator with the given {@code name} is - * already registered. - */ - void register(String name, ReactiveHealthIndicator healthIndicator); - - /** - * Unregisters the {@link ReactiveHealthIndicator} previously registered with the - * given {@code name}. - * @param name the name of the indicator - * @return the unregistered indicator, or {@code null} if no indicator was found in - * the registry for the given {@code name}. - */ - ReactiveHealthIndicator unregister(String name); - - /** - * Returns the {@link ReactiveHealthIndicator} registered with the given {@code name}. - * @param name the name of the indicator - * @return the health indicator, or {@code null} if no indicator was registered with - * the given {@code name}. - */ - ReactiveHealthIndicator get(String name); - - /** - * Returns a snapshot of the registered health indicators and their names. The - * contents of the map do not reflect subsequent changes to the registry. - * @return the snapshot of registered health indicators - */ - Map getAll(); - -} diff --git a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/ReactiveHealthIndicatorRegistryFactory.java b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/ReactiveHealthIndicatorRegistryFactory.java deleted file mode 100644 index d7939ac2a7e..00000000000 --- a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/ReactiveHealthIndicatorRegistryFactory.java +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Copyright 2012-2020 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.boot.actuate.health; - -import java.util.LinkedHashMap; -import java.util.Map; -import java.util.function.Function; - -import org.springframework.util.Assert; -import org.springframework.util.ObjectUtils; - -/** - * Factory to create a {@link HealthIndicatorRegistry}. - * - * @author Stephane Nicoll - * @since 2.1.0 - * @deprecated since 2.2.0 in favor of {@link DefaultReactiveHealthIndicatorRegistry} - */ -@Deprecated -public class ReactiveHealthIndicatorRegistryFactory { - - private final Function healthIndicatorNameFactory; - - public ReactiveHealthIndicatorRegistryFactory(Function healthIndicatorNameFactory) { - this.healthIndicatorNameFactory = healthIndicatorNameFactory; - } - - public ReactiveHealthIndicatorRegistryFactory() { - this(new HealthIndicatorNameFactory()); - } - - /** - * Create a {@link ReactiveHealthIndicatorRegistry} based on the specified health - * indicators. Each {@link HealthIndicator} are wrapped to a - * {@link HealthIndicatorReactiveAdapter}. If two instances share the same name, the - * reactive variant takes precedence. - * @param reactiveHealthIndicators the {@link ReactiveHealthIndicator} instances - * mapped by name - * @param healthIndicators the {@link HealthIndicator} instances mapped by name if - * any. - * @return a {@link ReactiveHealthIndicator} that delegates to the specified - * {@code reactiveHealthIndicators}. - */ - public ReactiveHealthIndicatorRegistry createReactiveHealthIndicatorRegistry( - Map reactiveHealthIndicators, - Map healthIndicators) { - Assert.notNull(reactiveHealthIndicators, "ReactiveHealthIndicators must not be null"); - return initialize(new DefaultReactiveHealthIndicatorRegistry(), reactiveHealthIndicators, healthIndicators); - } - - protected T initialize(T registry, - Map reactiveHealthIndicators, - Map healthIndicators) { - merge(reactiveHealthIndicators, healthIndicators).forEach((beanName, indicator) -> { - String name = this.healthIndicatorNameFactory.apply(beanName); - registry.register(name, indicator); - }); - return registry; - } - - private Map merge(Map reactiveHealthIndicators, - Map healthIndicators) { - if (ObjectUtils.isEmpty(healthIndicators)) { - return reactiveHealthIndicators; - } - Map allIndicators = new LinkedHashMap<>(reactiveHealthIndicators); - healthIndicators.forEach((beanName, indicator) -> { - String name = this.healthIndicatorNameFactory.apply(beanName); - allIndicators.computeIfAbsent(name, (n) -> new HealthIndicatorReactiveAdapter(indicator)); - }); - return allIndicators; - } - -} diff --git a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/CompositeHealthIndicatorTests.java b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/CompositeHealthIndicatorTests.java deleted file mode 100644 index 0ab8ce3ac25..00000000000 --- a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/CompositeHealthIndicatorTests.java +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Copyright 2012-2020 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.boot.actuate.health; - -import java.util.Collections; -import java.util.HashMap; -import java.util.LinkedHashMap; -import java.util.Map; - -import com.fasterxml.jackson.databind.ObjectMapper; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.mockito.Mock; -import org.mockito.MockitoAnnotations; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.BDDMockito.given; - -/** - * Tests for {@link CompositeHealthIndicator} - * - * @author Tyler J. Frederick - * @author Phillip Webb - * @author Christian Dupuis - */ -@Deprecated -class CompositeHealthIndicatorTests { - - private HealthAggregator healthAggregator; - - @Mock - private HealthIndicator one; - - @Mock - private HealthIndicator two; - - @BeforeEach - void setup() { - MockitoAnnotations.initMocks(this); - given(this.one.health()).willReturn(new Health.Builder().unknown().withDetail("1", "1").build()); - given(this.two.health()).willReturn(new Health.Builder().unknown().withDetail("2", "2").build()); - - this.healthAggregator = new OrderedHealthAggregator(); - } - - @Test - void createWithIndicators() { - Map indicators = new HashMap<>(); - indicators.put("one", this.one); - indicators.put("two", this.two); - CompositeHealthIndicator composite = new CompositeHealthIndicator(this.healthAggregator, indicators); - Health result = composite.health(); - assertThat(result.getDetails()).hasSize(2); - assertThat(result.getDetails()).containsEntry("one", - new Health.Builder().unknown().withDetail("1", "1").build()); - assertThat(result.getDetails()).containsEntry("two", - new Health.Builder().unknown().withDetail("2", "2").build()); - } - - @Test - void testSerialization() throws Exception { - Map indicators = new LinkedHashMap<>(); - indicators.put("db1", this.one); - indicators.put("db2", this.two); - CompositeHealthIndicator innerComposite = new CompositeHealthIndicator(this.healthAggregator, indicators); - CompositeHealthIndicator composite = new CompositeHealthIndicator(this.healthAggregator, - Collections.singletonMap("db", innerComposite)); - Health result = composite.health(); - ObjectMapper mapper = new ObjectMapper(); - assertThat(mapper.writeValueAsString(result)) - .isEqualTo("{\"status\":\"UNKNOWN\",\"details\":{\"db\":{\"status\":\"UNKNOWN\"" - + ",\"details\":{\"db1\":{\"status\":\"UNKNOWN\",\"details\"" - + ":{\"1\":\"1\"}},\"db2\":{\"status\":\"UNKNOWN\",\"details\":{\"2\":\"2\"}}}}}}"); - } - -} diff --git a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/CompositeReactiveHealthIndicatorTests.java b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/CompositeReactiveHealthIndicatorTests.java deleted file mode 100644 index b5793166850..00000000000 --- a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/CompositeReactiveHealthIndicatorTests.java +++ /dev/null @@ -1,120 +0,0 @@ -/* - * Copyright 2012-2020 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.boot.actuate.health; - -import java.time.Duration; -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; - -import org.junit.jupiter.api.Test; -import reactor.core.publisher.Mono; -import reactor.test.StepVerifier; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * Tests for {@link CompositeReactiveHealthIndicator}. - * - * @author Stephane Nicoll - */ -@Deprecated -class CompositeReactiveHealthIndicatorTests { - - private static final Health UNKNOWN_HEALTH = Health.unknown().withDetail("detail", "value").build(); - - private static final Health HEALTHY = Health.up().build(); - - private OrderedHealthAggregator healthAggregator = new OrderedHealthAggregator(); - - @Test - void singleIndicator() { - CompositeReactiveHealthIndicator indicator = new CompositeReactiveHealthIndicator(this.healthAggregator, - new DefaultReactiveHealthIndicatorRegistry(Collections.singletonMap("test", () -> Mono.just(HEALTHY)))); - StepVerifier.create(indicator.health()).consumeNextWith((h) -> { - assertThat(h.getStatus()).isEqualTo(Status.UP); - assertThat(h.getDetails()).containsOnlyKeys("test"); - assertThat(h.getDetails().get("test")).isEqualTo(HEALTHY); - }).verifyComplete(); - } - - @Test - void longHealth() { - Map indicators = new HashMap<>(); - for (int i = 0; i < 50; i++) { - indicators.put("test" + i, new TimeoutHealth(10000, Status.UP)); - } - CompositeReactiveHealthIndicator indicator = new CompositeReactiveHealthIndicator(this.healthAggregator, - new DefaultReactiveHealthIndicatorRegistry(indicators)); - StepVerifier.withVirtualTime(indicator::health).expectSubscription().thenAwait(Duration.ofMillis(10000)) - .consumeNextWith((h) -> { - assertThat(h.getStatus()).isEqualTo(Status.UP); - assertThat(h.getDetails()).hasSize(50); - }).verifyComplete(); - - } - - @Test - void timeoutReachedUsesFallback() { - Map indicators = new HashMap<>(); - indicators.put("slow", new TimeoutHealth(10000, Status.UP)); - indicators.put("fast", new TimeoutHealth(250, Status.UP)); - CompositeReactiveHealthIndicator indicator = new CompositeReactiveHealthIndicator(this.healthAggregator, - new DefaultReactiveHealthIndicatorRegistry(indicators)).timeoutStrategy(1000, UNKNOWN_HEALTH); - StepVerifier.create(indicator.health()).consumeNextWith((h) -> { - assertThat(h.getStatus()).isEqualTo(Status.UP); - assertThat(h.getDetails()).containsOnlyKeys("slow", "fast"); - assertThat(h.getDetails().get("slow")).isEqualTo(UNKNOWN_HEALTH); - assertThat(h.getDetails().get("fast")).isEqualTo(HEALTHY); - }).verifyComplete(); - } - - @Test - void timeoutNotReached() { - Map indicators = new HashMap<>(); - indicators.put("slow", new TimeoutHealth(10000, Status.UP)); - indicators.put("fast", new TimeoutHealth(10, Status.UP)); - CompositeReactiveHealthIndicator indicator = new CompositeReactiveHealthIndicator(this.healthAggregator, - new DefaultReactiveHealthIndicatorRegistry(indicators)).timeoutStrategy(20000, null); - StepVerifier.withVirtualTime(indicator::health).expectSubscription().thenAwait(Duration.ofMillis(10000)) - .consumeNextWith((h) -> { - assertThat(h.getStatus()).isEqualTo(Status.UP); - assertThat(h.getDetails()).containsOnlyKeys("slow", "fast"); - assertThat(h.getDetails().get("slow")).isEqualTo(HEALTHY); - assertThat(h.getDetails().get("fast")).isEqualTo(HEALTHY); - }).verifyComplete(); - } - - static class TimeoutHealth implements ReactiveHealthIndicator { - - private final long timeout; - - private final Status status; - - TimeoutHealth(long timeout, Status status) { - this.timeout = timeout; - this.status = status; - } - - @Override - public Mono health() { - return Mono.delay(Duration.ofMillis(this.timeout)).map((l) -> Health.status(this.status).build()); - } - - } - -} diff --git a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/DefaultHealthIndicatorRegistryTests.java b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/DefaultHealthIndicatorRegistryTests.java deleted file mode 100644 index bfd9bf661d5..00000000000 --- a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/DefaultHealthIndicatorRegistryTests.java +++ /dev/null @@ -1,103 +0,0 @@ -/* - * Copyright 2012-2020 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.boot.actuate.health; - -import java.util.Map; - -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatExceptionOfType; -import static org.assertj.core.api.Assertions.assertThatIllegalStateException; -import static org.mockito.BDDMockito.given; -import static org.mockito.Mockito.mock; - -/** - * Tests for {@link DefaultHealthIndicatorRegistry}. - * - * @author Vedran Pavic - * @author Stephane Nicoll - */ -@Deprecated -class DefaultHealthIndicatorRegistryTests { - - private HealthIndicator one = mock(HealthIndicator.class); - - private HealthIndicator two = mock(HealthIndicator.class); - - private DefaultHealthIndicatorRegistry registry; - - @BeforeEach - void setUp() { - given(this.one.health()).willReturn(new Health.Builder().unknown().withDetail("1", "1").build()); - given(this.two.health()).willReturn(new Health.Builder().unknown().withDetail("2", "2").build()); - this.registry = new DefaultHealthIndicatorRegistry(); - } - - @Test - void register() { - this.registry.register("one", this.one); - this.registry.register("two", this.two); - assertThat(this.registry.getAll()).hasSize(2); - assertThat(this.registry.get("one")).isSameAs(this.one); - assertThat(this.registry.get("two")).isSameAs(this.two); - } - - @Test - void registerAlreadyUsedName() { - this.registry.register("one", this.one); - assertThatIllegalStateException().isThrownBy(() -> this.registry.register("one", this.two)) - .withMessageContaining("HealthIndicator with name 'one' already registered"); - } - - @Test - void unregister() { - this.registry.register("one", this.one); - this.registry.register("two", this.two); - assertThat(this.registry.getAll()).hasSize(2); - HealthIndicator two = this.registry.unregister("two"); - assertThat(two).isSameAs(this.two); - assertThat(this.registry.getAll()).hasSize(1); - } - - @Test - void unregisterUnknown() { - this.registry.register("one", this.one); - assertThat(this.registry.getAll()).hasSize(1); - HealthIndicator two = this.registry.unregister("two"); - assertThat(two).isNull(); - assertThat(this.registry.getAll()).hasSize(1); - } - - @Test - void getAllIsASnapshot() { - this.registry.register("one", this.one); - Map snapshot = this.registry.getAll(); - assertThat(snapshot).containsOnlyKeys("one"); - this.registry.register("two", this.two); - assertThat(snapshot).containsOnlyKeys("one"); - } - - @Test - void getAllIsImmutable() { - this.registry.register("one", this.one); - Map snapshot = this.registry.getAll(); - assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(snapshot::clear); - } - -} diff --git a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/DefaultReactiveHealthIndicatorRegistryTests.java b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/DefaultReactiveHealthIndicatorRegistryTests.java deleted file mode 100644 index aa61417062b..00000000000 --- a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/DefaultReactiveHealthIndicatorRegistryTests.java +++ /dev/null @@ -1,104 +0,0 @@ -/* - * Copyright 2012-2020 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.boot.actuate.health; - -import java.util.Map; - -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import reactor.core.publisher.Mono; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatExceptionOfType; -import static org.assertj.core.api.Assertions.assertThatIllegalStateException; -import static org.mockito.BDDMockito.given; -import static org.mockito.Mockito.mock; - -/** - * Tests for {@link DefaultReactiveHealthIndicatorRegistry}. - * - * @author Vedran Pavic - * @author Stephane Nicoll - */ -@Deprecated -class DefaultReactiveHealthIndicatorRegistryTests { - - private ReactiveHealthIndicator one = mock(ReactiveHealthIndicator.class); - - private ReactiveHealthIndicator two = mock(ReactiveHealthIndicator.class); - - private DefaultReactiveHealthIndicatorRegistry registry; - - @BeforeEach - void setUp() { - given(this.one.health()).willReturn(Mono.just(new Health.Builder().unknown().withDetail("1", "1").build())); - given(this.two.health()).willReturn(Mono.just(new Health.Builder().unknown().withDetail("2", "2").build())); - this.registry = new DefaultReactiveHealthIndicatorRegistry(); - } - - @Test - void register() { - this.registry.register("one", this.one); - this.registry.register("two", this.two); - assertThat(this.registry.getAll()).hasSize(2); - assertThat(this.registry.get("one")).isSameAs(this.one); - assertThat(this.registry.get("two")).isSameAs(this.two); - } - - @Test - void registerAlreadyUsedName() { - this.registry.register("one", this.one); - assertThatIllegalStateException().isThrownBy(() -> this.registry.register("one", this.two)) - .withMessageContaining("HealthIndicator with name 'one' already registered"); - } - - @Test - void unregister() { - this.registry.register("one", this.one); - this.registry.register("two", this.two); - assertThat(this.registry.getAll()).hasSize(2); - ReactiveHealthIndicator two = this.registry.unregister("two"); - assertThat(two).isSameAs(this.two); - assertThat(this.registry.getAll()).hasSize(1); - } - - @Test - void unregisterUnknown() { - this.registry.register("one", this.one); - assertThat(this.registry.getAll()).hasSize(1); - ReactiveHealthIndicator two = this.registry.unregister("two"); - assertThat(two).isNull(); - assertThat(this.registry.getAll()).hasSize(1); - } - - @Test - void getAllIsASnapshot() { - this.registry.register("one", this.one); - Map snapshot = this.registry.getAll(); - assertThat(snapshot).containsOnlyKeys("one"); - this.registry.register("two", this.two); - assertThat(snapshot).containsOnlyKeys("one"); - } - - @Test - void getAllIsImmutable() { - this.registry.register("one", this.one); - Map snapshot = this.registry.getAll(); - assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(snapshot::clear); - } - -} diff --git a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/HealthIndicatorReactiveAdapterTests.java b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/HealthIndicatorReactiveAdapterTests.java index 4b3ec02fa08..1506c751f9b 100644 --- a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/HealthIndicatorReactiveAdapterTests.java +++ b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/HealthIndicatorReactiveAdapterTests.java @@ -29,7 +29,6 @@ import static org.mockito.Mockito.mock; * * @author Stephane Nicoll */ -@SuppressWarnings("deprecation") class HealthIndicatorReactiveAdapterTests { @Test diff --git a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/OrderedHealthAggregatorTests.java b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/OrderedHealthAggregatorTests.java deleted file mode 100644 index dfcfc85ac33..00000000000 --- a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/OrderedHealthAggregatorTests.java +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Copyright 2012-2020 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.boot.actuate.health; - -import java.util.Arrays; -import java.util.HashMap; -import java.util.Map; - -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * Tests for {@link OrderedHealthAggregator}. - * - * @author Christian Dupuis - */ -@Deprecated -class OrderedHealthAggregatorTests { - - private OrderedHealthAggregator healthAggregator; - - @BeforeEach - void setup() { - this.healthAggregator = new OrderedHealthAggregator(); - } - - @Test - void defaultOrder() { - Map healths = new HashMap<>(); - healths.put("h1", new Health.Builder().status(Status.DOWN).build()); - healths.put("h2", new Health.Builder().status(Status.UP).build()); - healths.put("h3", new Health.Builder().status(Status.UNKNOWN).build()); - healths.put("h4", new Health.Builder().status(Status.OUT_OF_SERVICE).build()); - assertThat(this.healthAggregator.aggregate(healths).getStatus()).isEqualTo(Status.DOWN); - } - - @Test - void customOrder() { - this.healthAggregator.setStatusOrder(Status.UNKNOWN, Status.UP, Status.OUT_OF_SERVICE, Status.DOWN); - Map healths = new HashMap<>(); - healths.put("h1", new Health.Builder().status(Status.DOWN).build()); - healths.put("h2", new Health.Builder().status(Status.UP).build()); - healths.put("h3", new Health.Builder().status(Status.UNKNOWN).build()); - healths.put("h4", new Health.Builder().status(Status.OUT_OF_SERVICE).build()); - assertThat(this.healthAggregator.aggregate(healths).getStatus()).isEqualTo(Status.UNKNOWN); - } - - @Test - void defaultOrderWithCustomStatus() { - Map healths = new HashMap<>(); - healths.put("h1", new Health.Builder().status(Status.DOWN).build()); - healths.put("h2", new Health.Builder().status(Status.UP).build()); - healths.put("h3", new Health.Builder().status(Status.UNKNOWN).build()); - healths.put("h4", new Health.Builder().status(Status.OUT_OF_SERVICE).build()); - healths.put("h5", new Health.Builder().status(new Status("CUSTOM")).build()); - assertThat(this.healthAggregator.aggregate(healths).getStatus()).isEqualTo(Status.DOWN); - } - - @Test - void customOrderWithCustomStatus() { - this.healthAggregator.setStatusOrder(Arrays.asList("DOWN", "OUT_OF_SERVICE", "UP", "UNKNOWN", "CUSTOM")); - Map healths = new HashMap<>(); - healths.put("h1", new Health.Builder().status(Status.DOWN).build()); - healths.put("h2", new Health.Builder().status(Status.UP).build()); - healths.put("h3", new Health.Builder().status(Status.UNKNOWN).build()); - healths.put("h4", new Health.Builder().status(Status.OUT_OF_SERVICE).build()); - healths.put("h5", new Health.Builder().status(new Status("CUSTOM")).build()); - assertThat(this.healthAggregator.aggregate(healths).getStatus()).isEqualTo(Status.DOWN); - } - -} diff --git a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/ReactiveHealthContributorTests.java b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/ReactiveHealthContributorTests.java index e0714db2dae..201d79e0acb 100644 --- a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/ReactiveHealthContributorTests.java +++ b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/ReactiveHealthContributorTests.java @@ -39,7 +39,6 @@ class ReactiveHealthContributorTests { } @Test - @SuppressWarnings("deprecation") void adaptWhenHealthIndicatorReturnsHealthIndicatorReactiveAdapter() { HealthIndicator indicator = () -> Health.outOfService().build(); ReactiveHealthContributor adapted = ReactiveHealthContributor.adapt(indicator); diff --git a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/ReactiveHealthIndicatorRegistryFactoryTests.java b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/ReactiveHealthIndicatorRegistryFactoryTests.java deleted file mode 100644 index 863992ff4e4..00000000000 --- a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/ReactiveHealthIndicatorRegistryFactoryTests.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright 2012-2020 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.boot.actuate.health; - -import java.util.Collections; - -import org.junit.jupiter.api.Test; -import reactor.core.publisher.Mono; -import reactor.test.StepVerifier; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * Tests for {@link ReactiveHealthIndicatorRegistryFactory}. - * - * @author Stephane Nicoll - */ -@Deprecated -class ReactiveHealthIndicatorRegistryFactoryTests { - - private static final Health UP = new Health.Builder().status(Status.UP).build(); - - private static final Health DOWN = new Health.Builder().status(Status.DOWN).build(); - - private final ReactiveHealthIndicatorRegistryFactory factory = new ReactiveHealthIndicatorRegistryFactory(); - - @Test - void defaultHealthIndicatorNameFactory() { - ReactiveHealthIndicatorRegistry registry = this.factory.createReactiveHealthIndicatorRegistry( - Collections.singletonMap("myHealthIndicator", () -> Mono.just(UP)), null); - assertThat(registry.getAll()).containsOnlyKeys("my"); - } - - @Test - void healthIndicatorIsAdapted() { - ReactiveHealthIndicatorRegistry registry = this.factory.createReactiveHealthIndicatorRegistry( - Collections.singletonMap("test", () -> Mono.just(UP)), Collections.singletonMap("regular", () -> DOWN)); - assertThat(registry.getAll()).containsOnlyKeys("test", "regular"); - StepVerifier.create(registry.get("regular").health()).consumeNextWith((h) -> { - assertThat(h.getStatus()).isEqualTo(Status.DOWN); - assertThat(h.getDetails()).isEmpty(); - }).verifyComplete(); - } - -} diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/ConfigurationBeanFactoryMetadata.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/ConfigurationBeanFactoryMetadata.java deleted file mode 100644 index 40350162460..00000000000 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/ConfigurationBeanFactoryMetadata.java +++ /dev/null @@ -1,93 +0,0 @@ -/* - * Copyright 2012-2020 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.boot.context.properties; - -import java.lang.annotation.Annotation; -import java.lang.reflect.Method; -import java.util.HashMap; -import java.util.Map; - -import org.springframework.beans.BeansException; -import org.springframework.beans.factory.config.BeanDefinition; -import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; -import org.springframework.beans.factory.support.BeanDefinitionBuilder; -import org.springframework.beans.factory.support.BeanDefinitionRegistry; -import org.springframework.beans.factory.support.RootBeanDefinition; -import org.springframework.context.ApplicationContext; -import org.springframework.context.ApplicationContextAware; -import org.springframework.context.ConfigurableApplicationContext; -import org.springframework.core.annotation.AnnotationUtils; - -/** - * Utility class to memorize {@code @Bean} definition metadata during initialization of - * the bean factory. - * - * @author Dave Syer - * @since 1.1.0 - * @deprecated since 2.2.0 in favor of {@link ConfigurationPropertiesBean} - */ -@Deprecated -public class ConfigurationBeanFactoryMetadata implements ApplicationContextAware { - - /** - * The bean name that this class is registered with. - */ - public static final String BEAN_NAME = ConfigurationBeanFactoryMetadata.class.getName(); - - private ConfigurableApplicationContext applicationContext; - - public Map getBeansWithFactoryAnnotation(Class type) { - Map result = new HashMap<>(); - for (String name : this.applicationContext.getBeanFactory().getBeanDefinitionNames()) { - if (findFactoryAnnotation(name, type) != null) { - result.put(name, this.applicationContext.getBean(name)); - } - } - return result; - } - - public A findFactoryAnnotation(String beanName, Class type) { - Method method = findFactoryMethod(beanName); - return (method != null) ? AnnotationUtils.findAnnotation(method, type) : null; - } - - public Method findFactoryMethod(String beanName) { - ConfigurableListableBeanFactory beanFactory = this.applicationContext.getBeanFactory(); - if (beanFactory.containsBeanDefinition(beanName)) { - BeanDefinition beanDefinition = beanFactory.getMergedBeanDefinition(beanName); - if (beanDefinition instanceof RootBeanDefinition) { - return ((RootBeanDefinition) beanDefinition).getResolvedFactoryMethod(); - } - } - return null; - } - - @Override - public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { - this.applicationContext = (ConfigurableApplicationContext) applicationContext; - } - - static void register(BeanDefinitionRegistry registry) { - if (!registry.containsBeanDefinition(BEAN_NAME)) { - BeanDefinition definition = BeanDefinitionBuilder.genericBeanDefinition( - ConfigurationBeanFactoryMetadata.class, ConfigurationBeanFactoryMetadata::new).getBeanDefinition(); - definition.setRole(BeanDefinition.ROLE_INFRASTRUCTURE); - registry.registerBeanDefinition(ConfigurationBeanFactoryMetadata.BEAN_NAME, definition); - } - } - -} diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/EnableConfigurationPropertiesRegistrar.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/EnableConfigurationPropertiesRegistrar.java index e4f0da6e504..fe093de5894 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/EnableConfigurationPropertiesRegistrar.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/EnableConfigurationPropertiesRegistrar.java @@ -48,11 +48,9 @@ class EnableConfigurationPropertiesRegistrar implements ImportBeanDefinitionRegi .filter((type) -> void.class != type).collect(Collectors.toSet()); } - @SuppressWarnings("deprecation") static void registerInfrastructureBeans(BeanDefinitionRegistry registry) { ConfigurationPropertiesBindingPostProcessor.register(registry); BoundConfigurationProperties.register(registry); - ConfigurationBeanFactoryMetadata.register(registry); } }