From ddc397dd05933e321bd4d38f5082c482ef56c3dc Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Tue, 11 Jun 2024 09:04:30 +0200 Subject: [PATCH 1/4] Upgrade to spring-javaformat-checkstyle 0.0.42 --- buildSrc/gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/buildSrc/gradle.properties b/buildSrc/gradle.properties index e3edacf40c..eacaf4f5b8 100644 --- a/buildSrc/gradle.properties +++ b/buildSrc/gradle.properties @@ -1,2 +1,2 @@ org.gradle.caching=true -javaFormatVersion=0.0.41 +javaFormatVersion=0.0.42 From e48f37d95631fc67c6e856a0a8634eb996f159b2 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Tue, 11 Jun 2024 09:05:48 +0200 Subject: [PATCH 2/4] Upgrade to Micrometer 1.12.7 Closes gh-33001 --- framework-platform/framework-platform.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/framework-platform/framework-platform.gradle b/framework-platform/framework-platform.gradle index 431ca0bd2a..845b4aa5ab 100644 --- a/framework-platform/framework-platform.gradle +++ b/framework-platform/framework-platform.gradle @@ -8,7 +8,7 @@ javaPlatform { dependencies { api(platform("com.fasterxml.jackson:jackson-bom:2.15.4")) - api(platform("io.micrometer:micrometer-bom:1.12.6")) + api(platform("io.micrometer:micrometer-bom:1.12.7")) api(platform("io.netty:netty-bom:4.1.110.Final")) api(platform("io.netty:netty5-bom:5.0.0.Alpha5")) api(platform("io.projectreactor:reactor-bom:2023.0.6")) From eca2b9657edc372fe77904565cb14f0f630ce697 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Tue, 11 Jun 2024 09:06:33 +0200 Subject: [PATCH 3/4] Documentation notes for @Bean overriding and bean name matching Closes gh-32825 --- .../autowired-qualifiers.adoc | 12 ++++----- .../ROOT/pages/core/beans/definition.adoc | 25 +++++++++++++++++++ 2 files changed, 30 insertions(+), 7 deletions(-) diff --git a/framework-docs/modules/ROOT/pages/core/beans/annotation-config/autowired-qualifiers.adoc b/framework-docs/modules/ROOT/pages/core/beans/annotation-config/autowired-qualifiers.adoc index ff9cad8976..34bf1e02b9 100644 --- a/framework-docs/modules/ROOT/pages/core/beans/annotation-config/autowired-qualifiers.adoc +++ b/framework-docs/modules/ROOT/pages/core/beans/annotation-config/autowired-qualifiers.adoc @@ -153,17 +153,15 @@ Letting qualifier values select against target bean names, within the type-match candidates, does not require a `@Qualifier` annotation at the injection point. If there is no other resolution indicator (such as a qualifier or a primary marker), for a non-unique dependency situation, Spring matches the injection point name -(that is, the field name or parameter name) against the target bean names and chooses the -same-named candidate, if any. +(that is, the field name or parameter name) against the target bean names and chooses +the same-named candidate, if any (either by bean name or by associated alias). Since version 6.1, this requires the `-parameters` Java compiler flag to be present. ==== -That said, if you intend to express annotation-driven injection by name, do not -primarily use `@Autowired`, even if it is capable of selecting by bean name among -type-matching candidates. Instead, use the JSR-250 `@Resource` annotation, which is -semantically defined to identify a specific target component by its unique name, with -the declared type being irrelevant for the matching process. `@Autowired` has rather +As an alternative for injection by name, consider the JSR-250 `@Resource` annotation +which is semantically defined to identify a specific target component by its unique name, +with the declared type being irrelevant for the matching process. `@Autowired` has rather different semantics: After selecting candidate beans by type, the specified `String` qualifier value is considered within those type-selected candidates only (for example, matching an `account` qualifier against beans marked with the same qualifier label). diff --git a/framework-docs/modules/ROOT/pages/core/beans/definition.adoc b/framework-docs/modules/ROOT/pages/core/beans/definition.adoc index 8de9ff4a17..56db659f58 100644 --- a/framework-docs/modules/ROOT/pages/core/beans/definition.adoc +++ b/framework-docs/modules/ROOT/pages/core/beans/definition.adoc @@ -75,6 +75,31 @@ lead to concurrent access exceptions, inconsistent state in the bean container, +[[beans-definition-overriding]] +== Overriding Beans + +Bean overriding is happening when a bean is registered using an identifier that is +already allocated. While bean overriding is possible, it makes the configuration harder +to read and this feature will be deprecated in a future release. + +To disable bean overriding altogether, you can set the `allowBeanDefinitionOverriding` +flag to `false` on the `ApplicationContext` before it is refreshed. In such setup, an +exception is thrown if bean overriding is used. + +By default, the container logs every bean overriding at `INFO` level so that you can +adapt your configuration accordingly. While not recommended, you can silence those logs +by setting the `allowBeanDefinitionOverriding` flag to `true`. + +.Java-configuration +**** +If you use Java Configuration, a corresponding `@Bean` method always silently overrides +a scanned bean class with the same component name as long as the return type of the +`@Bean` method matches that bean class. This simply means that the container will call +the `@Bean` factory method in favor of any pre-declared constructor on the bean class. +**** + + + [[beans-beanname]] == Naming Beans From fce2f49e46facf51dd9820b6e49be991994fbc08 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Tue, 11 Jun 2024 09:07:09 +0200 Subject: [PATCH 4/4] Polishing (aligned with main) --- .../support/DefaultLifecycleProcessor.java | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/spring-context/src/main/java/org/springframework/context/support/DefaultLifecycleProcessor.java b/spring-context/src/main/java/org/springframework/context/support/DefaultLifecycleProcessor.java index d353f33ad5..8e685b14c0 100644 --- a/spring-context/src/main/java/org/springframework/context/support/DefaultLifecycleProcessor.java +++ b/spring-context/src/main/java/org/springframework/context/support/DefaultLifecycleProcessor.java @@ -250,13 +250,13 @@ public class DefaultLifecycleProcessor implements LifecycleProcessor, BeanFactor lifecycleBeans.forEach((beanName, bean) -> { if (!autoStartupOnly || isAutoStartupCandidate(beanName, bean)) { - int phase = getPhase(bean); - phases.computeIfAbsent( - phase, - p -> new LifecycleGroup(phase, this.timeoutPerShutdownPhase, lifecycleBeans, autoStartupOnly) + int startupPhase = getPhase(bean); + phases.computeIfAbsent(startupPhase, + phase -> new LifecycleGroup(phase, this.timeoutPerShutdownPhase, lifecycleBeans, autoStartupOnly) ).add(beanName, bean); } }); + if (!phases.isEmpty()) { phases.values().forEach(LifecycleGroup::start); } @@ -307,13 +307,14 @@ public class DefaultLifecycleProcessor implements LifecycleProcessor, BeanFactor private void stopBeans() { Map lifecycleBeans = getLifecycleBeans(); Map phases = new TreeMap<>(Comparator.reverseOrder()); + lifecycleBeans.forEach((beanName, bean) -> { int shutdownPhase = getPhase(bean); - phases.computeIfAbsent( - shutdownPhase, - p -> new LifecycleGroup(shutdownPhase, this.timeoutPerShutdownPhase, lifecycleBeans, false) + phases.computeIfAbsent(shutdownPhase, + phase -> new LifecycleGroup(phase, this.timeoutPerShutdownPhase, lifecycleBeans, false) ).add(beanName, bean); }); + if (!phases.isEmpty()) { phases.values().forEach(LifecycleGroup::stop); }