Card 07/ 07
Recap: Wiring Beans Together
Constructor injection, stereotypes, ambiguous beans and @Bean methods, with where each was.
Wiring beans together comes down to the five ideas below, each listed with the card that covers it.
| The idea | Where |
|---|---|
| Constructor injection is the default: no half-built objects, every dependency in one place | Constructor Injection: Why It Is Spring's Default |
A class's only constructor needs no @Autowired | Constructor Injection Example: One Constructor, No @Autowired |
The four stereotypes register beans identically; @Repository also translates exceptions | @Component, @Service, @Repository and @Controller Compared |
Two candidates for one parameter stop startup; @Primary sets a default, @Qualifier picks one | Ambiguous Beans: Two Implementations of One Interface |
A class you cannot annotate becomes a bean through a @Bean method | @Bean Methods Example: Registering a Class You Cannot Annotate |
Most startup failures in a Spring application are one of these: a missing bean, two candidates for one parameter, or a class nobody told the container about.
← → move through sections and cards