Configuring a bean’s metadata using annotations
The Spring Framework provides lots of annotations to configure the metadata for beans. However, we’ll focus on the most used annotations: @Autowired, @Qualifier, @Inject, @Resource, @Primary, and @Value.
How to use @Autowired?
The @Autowired annotation allows you to define the configuration in a bean’s class itself, instead of writing a separate configuration class annotated with @Configuration.
The @Autowired annotation can be applied to a field (as we saw in the class property-based DI example), constructor, setter, or any method.
The Spring container makes use of reflections to inject the beans annotated with @Autowired. This also makes it more costly than other injection approaches.
Please make a note that applying @Autowired to class members will only work if there is no constructor or setter method to inject the dependent bean.
Here is a code example demonstrating the use of @Autowired to inject...