What this animation explains
A single-valued required injection point needs one resolvable candidate. No match causes a missing dependency; multiple equally eligible candidates without a qualifier, primary or other tie-breaker cause ambiguity.

MODULE 4 · TOPIC 7 · VISUAL SPRING FRAMEWORK LAB
Autowiring is Spring’s mechanism for resolving injection points from registered bean definitions. Candidate selection primarily uses type, then qualifying metadata, primary/fallback status and other resolution rules such as matching names. A single required injection point must resolve unambiguously. Collections may receive multiple beans; optional injection and providers express a different contract. Component scanning registers beans, while autowiring connects them.
Browser-based Spring simulations. Change inputs and trace bean wiring, application layers, configuration and transaction behavior. No real Java, Spring or database operations are executed.
A single-valued required injection point needs one resolvable candidate. No match causes a missing dependency; multiple equally eligible candidates without a qualifier, primary or other tie-breaker cause ambiguity.
Why this example? Change the number of registered Notifier beans.
Arrows show the actual route; blue identifies the current node. Green indicates visited operations; red nodes show errors or rejected paths.
Change inputs and step through the example. Code and output are illustrative; actual Spring logs and initialization order may differ. Use the worked examples in a real project.
A single-valued required injection point needs one resolvable candidate. No match causes a missing dependency; multiple equally eligible candidates without a qualifier, primary or other tie-breaker cause ambiguity.
Watch the candidate count and the outcome.
@Primary gives preference when multiple eligible beans satisfy a single-valued injection. A qualifier narrows the set first; it can select a nonprimary implementation. Primary does not hide other registered beans.
Why this example? Choose unqualified or qualified injection of email and sms.
Arrows show the actual route; blue identifies the current node. Green indicates visited operations; red nodes show errors or rejected paths.
Change inputs and step through the example. Code and output are illustrative; actual Spring logs and initialization order may differ. Use the worked examples in a real project.
@Primary gives preference when multiple eligible beans satisfy a single-valued injection. A qualifier narrows the set first; it can select a nonprimary implementation. Primary does not hide other registered beans.
Inspect the candidate chosen and output channel.
List<T> injection gathers eligible matching beans and can honor @Order/Ordered ordering. It differs from scalar injection: @Primary does not exclude the other beans. @Order is not a general singleton startup-order guarantee.
Why this example? Compare a scalar Notifier with a list of Notifiers.
Arrows show the actual route; blue identifies the current node. Green indicates visited operations; red nodes show errors or rejected paths.
Change inputs and step through the example. Code and output are illustrative; actual Spring logs and initialization order may differ. Use the worked examples in a real project.
List<T> injection gathers eligible matching beans and can honor @Order/Ordered ordering. It differs from scalar injection: @Primary does not exclude the other beans. @Order is not a general singleton startup-order guarantee.
Observe invocation count and output order.
Autowired fields are populated by container post-processing after object construction. Methods are also injection points. Objects constructed manually with new are not automatically post-processed by Spring.
Why this example? Compare a container-managed component and a manually constructed instance.
Arrows show the actual route; blue identifies the current node. Green indicates visited operations; red nodes show errors or rejected paths.
Change inputs and step through the example. Code and output are illustrative; actual Spring logs and initialization order may differ. Use the worked examples in a real project.
Autowired fields are populated by container post-processing after object construction. Methods are also injection points. Objects constructed manually with new are not automatically post-processed by Spring.
Check why the field remains null outside the container.
Optional<T> supports absence for one expected dependency. ObjectProvider<T> can resolve on demand; getIfAvailable returns null for absence, but neither removes ambiguity when multiple unresolved candidates exist.
Why this example? Compare the provider with and without a registered audit bean.
Arrows show the actual route; blue identifies the current node. Green indicates visited operations; red nodes show errors or rejected paths.
Change inputs and step through the example. Code and output are illustrative; actual Spring logs and initialization order may differ. Use the worked examples in a real project.
Optional<T> supports absence for one expected dependency. ObjectProvider<T> can resolve on demand; getIfAvailable returns null for absence, but neither removes ambiguity when multiple unresolved candidates exist.
Watch lookup at method execution instead of startup.
Qualifiers narrow eligible type candidates. A typo can eliminate all matches even though beans of that type exist. Error messages and registry inspection help separate registration problems from selection problems.
Why this example? Compare matching and misspelled qualifiers.
Arrows show the actual route; blue identifies the current node. Green indicates visited operations; red nodes show errors or rejected paths.
Change inputs and step through the example. Code and output are illustrative; actual Spring logs and initialization order may differ. Use the worked examples in a real project.
Qualifiers narrow eligible type candidates. A typo can eliminate all matches even though beans of that type exist. Error messages and registry inspection help separate registration problems from selection problems.
Inspect registered beans and the exact qualifier value.
Refer to these APIs and settings while building a real Spring project.
| API / setting | Why and when to use it |
|---|---|
| @Autowired | Resolve a dependency from the container |
| @Qualifier("email") | Narrow type-matching candidates |
| @Primary | Prefer one candidate for a single-valued injection point |
| @Order | Order eligible collection elements |
| Optional<T> | Represent an optional collaborator |
| ObjectProvider<T> | Perform deferred lookup |
Follow these procedures with the Java 21 / Spring Framework 6.2.0 teaching project. Unless complete files are provided, the code is a focused snippet requiring the indicated imports, companion classes and configuration.
@Configuration
class Config {
@Bean @Primary Notifier email() { return m -> System.out.println("EMAIL " + m); }
@Bean Notifier sms() { return m -> System.out.println("SMS " + m); }
@Bean AlertService alerts(@Qualifier("sms") Notifier n) { return new AlertService(n); }
}@Service
class BroadcastService {
private final List<Notifier> all;
BroadcastService(List<Notifier> all) { this.all = all; }
void send(String m) { all.forEach(n -> n.send(m)); }
}Try answering these questions, then expand each answer and repeat the appropriate simulation.
Spring cannot choose a unique object. Expected state: NoUniqueBeanDefinitionException.
Invoke Email second. Expected state: 2 of 2.
The guard avoids dereferencing null. Expected state: null.
Register two Notifier implementations. Resolve one using @Primary or @Qualifier, then inject List<Notifier> to observe both.
Edit this practice scratchpad and copy it into your real Java project. The browser does not compile arbitrary Java.
Do not use bean names accidentally to resolve ambiguity. Use explicit qualifier metadata when implementations have distinct roles. Examples use ordinary single-bean type resolution.