From bff2c95fe1fc6c49c3e848362b8036c8b9e00da2 Mon Sep 17 00:00:00 2001 From: Yanming Zhou Date: Fri, 24 Jan 2025 23:55:10 +0800 Subject: [PATCH 1/6] Support configuring bean names as well as bean types for extra-refreshable and never-refreshable (#1457) Thanks to https://github.com/spring-projects/spring-boot/issues/22403, applications could define a bean in addition to an auto-configured bean of the same type, then we should support configuring bean names for fine-grained control. Signed-off-by: Yanming Zhou --- docs/modules/ROOT/partials/_configprops.adoc | 4 +-- .../RefreshAutoConfiguration.java | 6 +++- .../ConfigurationPropertiesRebinder.java | 5 ++-- ...itional-spring-configuration-metadata.json | 4 +-- .../RefreshAutoConfigurationTests.java | 28 +++++++++++++++++-- 5 files changed, 37 insertions(+), 10 deletions(-) diff --git a/docs/modules/ROOT/partials/_configprops.adoc b/docs/modules/ROOT/partials/_configprops.adoc index 7d261e79..d3c42cdc 100644 --- a/docs/modules/ROOT/partials/_configprops.adoc +++ b/docs/modules/ROOT/partials/_configprops.adoc @@ -76,8 +76,8 @@ |spring.cloud.loadbalancer.zone | | Spring Cloud LoadBalancer zone. |spring.cloud.refresh.additional-property-sources-to-retain | | Additional property sources to retain during a refresh. Typically only system property sources are retained. This property allows property sources, such as property sources created by EnvironmentPostProcessors to be retained as well. |spring.cloud.refresh.enabled | `+++true+++` | Enables autoconfiguration for the refresh scope and associated features. -|spring.cloud.refresh.extra-refreshable | `+++true+++` | Additional class names for beans to post process into refresh scope. -|spring.cloud.refresh.never-refreshable | `+++true+++` | Comma separated list of class names for beans to never be refreshed or rebound. +|spring.cloud.refresh.extra-refreshable | `+++true+++` | Additional bean names or class names for beans to post process into refresh scope. +|spring.cloud.refresh.never-refreshable | `+++true+++` | Comma separated list of bean names or class names for beans to never be refreshed or rebound. |spring.cloud.refresh.on-restart.enabled | `+++true+++` | Enable refreshing context on start. |spring.cloud.service-registry.auto-registration.enabled | `+++true+++` | Whether service auto-registration is enabled. Defaults to true. |spring.cloud.service-registry.auto-registration.fail-fast | `+++false+++` | Whether startup fails if there is no AutoServiceRegistration. Defaults to false. diff --git a/spring-cloud-context/src/main/java/org/springframework/cloud/autoconfigure/RefreshAutoConfiguration.java b/spring-cloud-context/src/main/java/org/springframework/cloud/autoconfigure/RefreshAutoConfiguration.java index 57e26fc0..6f801218 100644 --- a/spring-cloud-context/src/main/java/org/springframework/cloud/autoconfigure/RefreshAutoConfiguration.java +++ b/spring-cloud-context/src/main/java/org/springframework/cloud/autoconfigure/RefreshAutoConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2020 the original author or authors. + * Copyright 2012-2025 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. @@ -63,6 +63,7 @@ import org.springframework.util.StringUtils; * @author Dave Syer * @author Venil Noronha * @author Olga Maciaszek-Sharma + * @author Yanming Zhou */ @Configuration(proxyBeanMethods = false) @ConditionalOnClass(RefreshScope.class) @@ -209,6 +210,9 @@ public class RefreshAutoConfiguration { // Already refresh scoped return false; } + if (this.refreshables.contains(name)) { + return true; + } String type = definition.getBeanClassName(); if (!StringUtils.hasText(type) && registry instanceof BeanFactory) { Class cls = ((BeanFactory) registry).getType(name); diff --git a/spring-cloud-context/src/main/java/org/springframework/cloud/context/properties/ConfigurationPropertiesRebinder.java b/spring-cloud-context/src/main/java/org/springframework/cloud/context/properties/ConfigurationPropertiesRebinder.java index ca2e9d79..a2359c74 100644 --- a/spring-cloud-context/src/main/java/org/springframework/cloud/context/properties/ConfigurationPropertiesRebinder.java +++ b/spring-cloud-context/src/main/java/org/springframework/cloud/context/properties/ConfigurationPropertiesRebinder.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2020 the original author or authors. + * Copyright 2012-2025 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. @@ -47,6 +47,7 @@ import org.springframework.util.StringUtils; * the @ConfigurationProperties bean. * * @author Dave Syer + * @author Yanming Zhou * @see RefreshScope for a deeper and optionally more focused refresh of bean components. * */ @@ -131,7 +132,7 @@ public class ConfigurationPropertiesRebinder // TODO: determine a more general approach to fix this. // see // https://github.com/spring-cloud/spring-cloud-commons/issues/571 - if (getNeverRefreshable().contains(bean.getClass().getName())) { + if (getNeverRefreshable().contains(bean.getClass().getName()) || getNeverRefreshable().contains(name)) { return false; // ignore } appContext.getAutowireCapableBeanFactory().destroyBean(bean); diff --git a/spring-cloud-context/src/main/resources/META-INF/additional-spring-configuration-metadata.json b/spring-cloud-context/src/main/resources/META-INF/additional-spring-configuration-metadata.json index 448ce8fe..ff535a76 100644 --- a/spring-cloud-context/src/main/resources/META-INF/additional-spring-configuration-metadata.json +++ b/spring-cloud-context/src/main/resources/META-INF/additional-spring-configuration-metadata.json @@ -39,13 +39,13 @@ { "name": "spring.cloud.refresh.extra-refreshable", "type": "java.util.Set", - "description": "Additional class names for beans to post process into refresh scope.", + "description": "Additional bean names or class names for beans to post process into refresh scope.", "defaultValue": true }, { "name": "spring.cloud.refresh.never-refreshable", "type": "java.lang.String", - "description": "Comma separated list of class names for beans to never be refreshed or rebound.", + "description": "Comma separated list of bean names or class names for beans to never be refreshed or rebound.", "defaultValue": true }, { diff --git a/spring-cloud-context/src/test/java/org/springframework/cloud/autoconfigure/RefreshAutoConfigurationTests.java b/spring-cloud-context/src/test/java/org/springframework/cloud/autoconfigure/RefreshAutoConfigurationTests.java index 03d30c1f..4786f244 100644 --- a/spring-cloud-context/src/test/java/org/springframework/cloud/autoconfigure/RefreshAutoConfigurationTests.java +++ b/spring-cloud-context/src/test/java/org/springframework/cloud/autoconfigure/RefreshAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2020 the original author or authors. + * Copyright 2012-2025 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. @@ -41,6 +41,7 @@ import static org.assertj.core.api.BDDAssertions.then; /** * @author Dave Syer * @author Olga Maciaszek-Sharma + * @author Yanming Zhou */ @ExtendWith(OutputCaptureExtension.class) class RefreshAutoConfigurationTests { @@ -79,7 +80,7 @@ class RefreshAutoConfigurationTests { } @Test - public void extraRefreshables() { + public void extraRefreshableWithClassName() { try (ConfigurableApplicationContext context = getApplicationContext(WebApplicationType.NONE, Config.class, "sealedconfig.foo=bar", "spring.cloud.refresh.extra-refreshable:" + SealedConfigProps.class.getName())) { @@ -89,7 +90,17 @@ class RefreshAutoConfigurationTests { } @Test - void neverRefreshable() { + public void extraRefreshableWithBeanName() { + String beanName = "sealedconfig-" + SealedConfigProps.class.getName(); + try (ConfigurableApplicationContext context = getApplicationContext(WebApplicationType.NONE, Config.class, + "sealedconfig.foo=bar", "spring.cloud.refresh.extra-refreshable:" + beanName)) { + context.getBean(SealedConfigProps.class); + context.getBean(ContextRefresher.class).refresh(); + } + } + + @Test + void neverRefreshableWithClassName() { try (ConfigurableApplicationContext context = getApplicationContext(WebApplicationType.NONE, Config.class, "countingconfig.foo=bar", "spring.cloud.refresh.never-refreshable:" + CountingConfigProps.class.getName())) { @@ -99,6 +110,17 @@ class RefreshAutoConfigurationTests { } } + @Test + void neverRefreshableWithBeanName() { + String beanName = "countingconfig-" + CountingConfigProps.class.getName(); + try (ConfigurableApplicationContext context = getApplicationContext(WebApplicationType.NONE, Config.class, + "countingconfig.foo=bar", "spring.cloud.refresh.never-refreshable:" + beanName)) { + CountingConfigProps configProps = context.getBean(CountingConfigProps.class); + context.getBean(ContextRefresher.class).refresh(); + assertThat(configProps.count).as("config props was rebound when it should not have been").hasValue(1); + } + } + @Test void refreshScopeLifecylePresentByDefault() { new ApplicationContextRunner().withConfiguration(AutoConfigurations.of(RefreshAutoConfiguration.class)) From b9dca6f5097fa0e8c6d12ec501570602c4c1d9f2 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 3 Feb 2025 10:23:13 -0500 Subject: [PATCH 2/6] Bump @springio/asciidoctor-extensions in /docs (#1459) Bumps [@springio/asciidoctor-extensions](https://github.com/spring-io/asciidoctor-extensions) from 1.0.0-alpha.14 to 1.0.0-alpha.16. - [Changelog](https://github.com/spring-io/asciidoctor-extensions/blob/main/CHANGELOG.adoc) - [Commits](https://github.com/spring-io/asciidoctor-extensions/compare/v1.0.0-alpha.14...v1.0.0-alpha.16) --- updated-dependencies: - dependency-name: "@springio/asciidoctor-extensions" dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- docs/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/package.json b/docs/package.json index ca5b2ce8..755f9ee7 100644 --- a/docs/package.json +++ b/docs/package.json @@ -5,6 +5,6 @@ "@antora/collector-extension": "1.0.1", "@asciidoctor/tabs": "1.0.0-beta.6", "@springio/antora-extensions": "1.14.2", - "@springio/asciidoctor-extensions": "1.0.0-alpha.14" + "@springio/asciidoctor-extensions": "1.0.0-alpha.16" } } From 531f273339d0d0b94336181df4d2c25319694a17 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 3 Feb 2025 10:36:11 -0500 Subject: [PATCH 3/6] Bump @springio/asciidoctor-extensions in /docs (#1462) Bumps [@springio/asciidoctor-extensions](https://github.com/spring-io/asciidoctor-extensions) from 1.0.0-alpha.14 to 1.0.0-alpha.16. - [Changelog](https://github.com/spring-io/asciidoctor-extensions/blob/main/CHANGELOG.adoc) - [Commits](https://github.com/spring-io/asciidoctor-extensions/compare/v1.0.0-alpha.14...v1.0.0-alpha.16) --- updated-dependencies: - dependency-name: "@springio/asciidoctor-extensions" dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- docs/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/package.json b/docs/package.json index 567c1f3a..1e55982d 100644 --- a/docs/package.json +++ b/docs/package.json @@ -5,6 +5,6 @@ "@antora/collector-extension": "1.0.1", "@asciidoctor/tabs": "1.0.0-beta.6", "@springio/antora-extensions": "1.14.2", - "@springio/asciidoctor-extensions": "1.0.0-alpha.14" + "@springio/asciidoctor-extensions": "1.0.0-alpha.16" } } From c8cade1a7d5f4363350ca375dbebddb22b9baa13 Mon Sep 17 00:00:00 2001 From: Ryan Baxter Date: Mon, 3 Feb 2025 10:39:21 -0500 Subject: [PATCH 4/6] Update maven.yml Signed-off-by: Ryan Baxter --- .github/workflows/maven.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 9d5357d8..80b3cfb7 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -5,9 +5,9 @@ name: Build on: push: - branches: [ main, 4.1.x ] + branches: [ main, 4.2.x, 4.1.x ] pull_request: - branches: [ main, 4.1.x ] + branches: [ main, 4.2.x, 4.1.x ] jobs: build: From 12395661e1883e24bce9828953526e1b75d6f3b0 Mon Sep 17 00:00:00 2001 From: Ryan Baxter Date: Fri, 14 Feb 2025 10:06:21 -0500 Subject: [PATCH 5/6] Manage the version of okhttp in commons (#1470) --- spring-cloud-commons-dependencies/pom.xml | 15 +++++++++++++++ spring-cloud-commons/pom.xml | 10 ++++++++++ 2 files changed, 25 insertions(+) diff --git a/spring-cloud-commons-dependencies/pom.xml b/spring-cloud-commons-dependencies/pom.xml index af72a3c7..9fc5a88d 100644 --- a/spring-cloud-commons-dependencies/pom.xml +++ b/spring-cloud-commons-dependencies/pom.xml @@ -15,6 +15,7 @@ spring-cloud-commons-dependencies Spring Cloud Commons Dependencies + 4.12.0 @@ -53,6 +54,20 @@ spring-cloud-test-support ${project.version} + + + + + + com.squareup.okhttp3 + okhttp + ${okhttp.version} + + + com.squareup.okhttp3 + logging-interceptor + ${okhttp.version} + diff --git a/spring-cloud-commons/pom.xml b/spring-cloud-commons/pom.xml index a0c55a7c..cfe4621e 100644 --- a/spring-cloud-commons/pom.xml +++ b/spring-cloud-commons/pom.xml @@ -176,6 +176,16 @@ httpclient5 true + + com.squareup.okhttp3 + okhttp + true + + + com.squareup.okhttp3 + logging-interceptor + true + org.springframework.boot spring-boot-starter-test From a196c33610b2b3c755535c5edf2993841b3f99d3 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 4 Mar 2025 15:29:02 +0100 Subject: [PATCH 6/6] Bump @springio/antora-extensions from 1.14.2 to 1.14.4 in /docs (#1474) Bumps [@springio/antora-extensions](https://github.com/spring-io/antora-extensions) from 1.14.2 to 1.14.4. - [Changelog](https://github.com/spring-io/antora-extensions/blob/main/CHANGELOG.adoc) - [Commits](https://github.com/spring-io/antora-extensions/compare/v1.14.2...v1.14.4) --- updated-dependencies: - dependency-name: "@springio/antora-extensions" dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- docs/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/package.json b/docs/package.json index 755f9ee7..9e455a6d 100644 --- a/docs/package.json +++ b/docs/package.json @@ -4,7 +4,7 @@ "@antora/atlas-extension": "1.0.0-alpha.2", "@antora/collector-extension": "1.0.1", "@asciidoctor/tabs": "1.0.0-beta.6", - "@springio/antora-extensions": "1.14.2", + "@springio/antora-extensions": "1.14.4", "@springio/asciidoctor-extensions": "1.0.0-alpha.16" } }