Core Spring Framework Annotations
The spring supports a large set of annotations for handling different situations. Over this article, we are exploring the annotations in the spring core framework.
Over this article, we are discussing the spring core annotations such as @Autowire, @Qualifier, @Configuration, @Bean, @ComponentScan, @Lazy, and @Value. We will cover all these annotations with examples.
@Autowire
From Spring 2.5, the framework introduced annotations-driven Dependency Injection. The main annotation that comes as part of this feature is @Autowired. It allows Spring to resolve and inject collaborating beans into our bean.
The @Autowired annotation is the most used way to inject the dependencies in Spring. By default, the @Autowired resolve dependencies by type. This works fine until we have only one bean with the same type.But the Spring framework will throw an exception if there are two beans with same type is available in the container. The @Autowired annotation will not work in this case. Because spring doesnt know which beans needs to autowire there.
In spring there are two types of autowiring. Those are
- Autowiring by type.
- Autowiring by name.
Autowiring by type: @Autowired
by type uses the class type to autowire the…