Core Spring Framework Annotations

Anish Antony
Javarevisited
Published in
7 min readApr 22, 2021

--

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.

Photo by Victoria Strukovskaya on Unsplash

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…

--

--

Anish Antony
Javarevisited

Fullstack Developer | Blogger | Experience on Java, Python, React, Angular, Golang | http://www.behindjava.com