@Autowired is heavily used in Spring for injecting dependencies. By entrusting the framework itself to inject dependencies (e.g. repositories interface), the programmer can rest assured and focus on the core business logic of the application.

We can also use @Autowired in order to initialize Java collections which use generics. Let's say we have an interface which could be implemented by a given number of classes. We can register each of those classes in Spring Context with the @Context annotation. Optionally, we can also name the component using @Component($name). This becomes particularly useful if we want to associate each context with a keyword. Using component name also enables us to qualify the required bean whenever Spring tries to autowire using Qualifier($beanName). One use case could be that the keyword is the JSON field name and the corresponding class is the utility class to operate on the model associated with that JSON.

Spring now scans for all the implementations of "GenericUpdater" and injects them into this map keyed with the name given in @Component($name). Here we can see the importance of naming the beans. Since each implementation of GenericUpdater has a custom name defined, there is no ambiguity while we try to fetch the beans.

BloomReach CMS: the API-first CMS of the future. Open-source & enterprise-grade. - As a Java developer, you will feel at home using Maven builds and your favorite IDE (e.g. Eclipse or IntelliJ) and continuous integration server (e.g. Jenkins). Manage your Java objects using Spring Framework, write your templates in JSP or Freemarker. Try for free.