Browse Source

Polishing

pull/33048/head
Juergen Hoeller 2 years ago
parent
commit
b9eeee8341
  1. 15
      framework-docs/modules/ROOT/pages/core/beans/annotation-config/autowired-qualifiers.adoc
  2. 6
      framework-docs/modules/ROOT/pages/core/beans/definition.adoc
  3. 10
      spring-context/src/main/java/org/springframework/context/support/DefaultLifecycleProcessor.java

15
framework-docs/modules/ROOT/pages/core/beans/annotation-config/autowired-qualifiers.adoc

@ -153,15 +153,16 @@ Letting qualifier values select against target bean names, within the type-match @@ -153,15 +153,16 @@ 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).
This requires the `-parameters` Java compiler flag to be present. As a fallback,
version 6.0 still supports parameter names from debug symbols via `-debug` as well.
====
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).

6
framework-docs/modules/ROOT/pages/core/beans/definition.adoc

@ -416,8 +416,8 @@ Kotlin:: @@ -416,8 +416,8 @@ Kotlin::
======
This approach shows that the factory bean itself can be managed and configured through
dependency injection (DI). See xref:core/beans/dependencies/factory-properties-detailed.adoc[Dependencies and Configuration in Detail]
.
dependency injection (DI).
See xref:core/beans/dependencies/factory-properties-detailed.adoc[Dependencies and Configuration in Detail].
NOTE: In Spring documentation, "factory bean" refers to a bean that is configured in the
Spring container and that creates objects through an
@ -444,5 +444,3 @@ cases into account and returns the type of object that a `BeanFactory.getBean` c @@ -444,5 +444,3 @@ cases into account and returns the type of object that a `BeanFactory.getBean` c
going to return for the same bean name.

10
spring-context/src/main/java/org/springframework/context/support/DefaultLifecycleProcessor.java

@ -149,13 +149,13 @@ public class DefaultLifecycleProcessor implements LifecycleProcessor, BeanFactor @@ -149,13 +149,13 @@ public class DefaultLifecycleProcessor implements LifecycleProcessor, BeanFactor
lifecycleBeans.forEach((beanName, bean) -> {
if (!autoStartupOnly || (bean instanceof SmartLifecycle smartLifecycle && smartLifecycle.isAutoStartup())) {
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);
}
@ -195,6 +195,7 @@ public class DefaultLifecycleProcessor implements LifecycleProcessor, BeanFactor @@ -195,6 +195,7 @@ public class DefaultLifecycleProcessor implements LifecycleProcessor, BeanFactor
private void stopBeans() {
Map<String, Lifecycle> lifecycleBeans = getLifecycleBeans();
Map<Integer, LifecycleGroup> phases = new HashMap<>();
lifecycleBeans.forEach((beanName, bean) -> {
int shutdownPhase = getPhase(bean);
LifecycleGroup group = phases.get(shutdownPhase);
@ -204,6 +205,7 @@ public class DefaultLifecycleProcessor implements LifecycleProcessor, BeanFactor @@ -204,6 +205,7 @@ public class DefaultLifecycleProcessor implements LifecycleProcessor, BeanFactor
}
group.add(beanName, bean);
});
if (!phases.isEmpty()) {
List<Integer> keys = new ArrayList<>(phases.keySet());
keys.sort(Collections.reverseOrder());

Loading…
Cancel
Save