Spring Boot Annotations List
Let us read the different Spring Boot Annotations given below:
- @Bean
- @Service
- @Configuration
- @Repository
- @Controller
- @RequestMapping
- @Autowired
- @Component
- @EnableAutoConfiguration
- @SpringBootApplication
- @ComponetScan
- @Required
- @Qualifier
- @CookieValue
- @Lazy
The @Bean is used at the method levels, indicating that a method generates a bean that the Spring container should manage. It's a replacement for the XML <bean> tag.
Example:
@Bean
Public BeanExample beanExample ()
{
return new BeanExample (),
}
It represents that the annotated class is a service class, which can call external APIs and perform essential business logic.
Example:
@Service
public class TestService
{
public void service1()
{
// business code
}
}
It's an excellent place to look for bean definitions. It's an annotation at the class level.
Example:
@Configuration
public class Bus
{
@BeanBus engine()
{
return new Bus();
}
}
It's a Data Access Object (DAO) that connects directly to the database. It denotes the repository nature of the annotated class.
Example:
@Repository
public class TestRepository
{
public void delete()
{
// code
}
}
The annotation signifies that the class is a web request handler. It is frequently used to display web pages. It's usually combined with the @RequestMapping annotation.
Example:
@Controller
@RequestMapping("Web")
public class WebNinjaController
{
@RequestMapping(value= "/{name}", method= RequestMethod.GET)
public Employee WebNinjaByName()
{
Return webNinjaTemplate;
}
}
The HTTP request is mapped using RequestMapping. It can be used with both the class and the method. There are numerous other optional elements, such as consumes, name, method, request, path, etc.
Example:
@Controller
public class NinjaController
{
@RequestMapping ("/web-course/ninjas")
public String getAllNinja(Model model)
{
//code of an application
return "ninjalist";
}
This annotation is used to auto-wire the spring bean on setter methods, constructors, and instance variables. It implicitly injects object dependency. When we use this annotation, the spring container automatically wires the bean to its matching data type.
Example:
@Component
public class Ninja
private Person person;
@Autowired
public Employee(Person person)
{
this.person=person
}
}
It's a class-level annotation that, during auto-scan, transforms the class into a Spring bean.
Example:
@Component
Public class Teachers
{
......
}
It's in the application's main class. This annotation tells SpringBoot to start adding beans based on classpath settings, other beans, and various property settings. The use of this annotation was reduced in Spring Boot 1.2.0 because developers provided an alternative, namely @SpringBootApplication.
The @Configuration, @ComponentScan, and @EnabeAutoConfiguration are the three components of @SpringBootApplication. The @SpringBootApplication-annotated class is kept in the base package. This annotation performs the component scan. Only the sub-packages, however, are scanned.

A package of beans is scanned with it. It's used in conjunction with the annotation @Configuration to tell Spring which packages to look for annotated components. This annotation can also be used to indicate the base packages.
Example:
@ComponentScan(basePackages = "com.xyz")
@Configuration
Public class ScanComponent
{
//...
}
Bean setter methods are annotated with this annotation. It indicates that the required property in the affected bean must be filled at configuration time, or else an exception will be thrown: BeanInitializationException.
It's used in conjunction with the @Autowired annotation and when more control over the dependency injection process is required. The @Qualifier is used to clear things up when more than one bean of the same type is created, but only one of them needs to be wired with a property.
It is used as an argument of the request mapping method at the method parameter level. The HTTP cookie is bound to a @CookieValue parameter for a given cookie name.
The component class uses it. All auto-wired dependencies are created and configured at startup. If a bean is to be initialized slowly, a @Lazy annotation can be used. This means that a bean will only be created if it is requested. It's also applicable to @Configuartion classes. It means that all @Bean methods in that @Configuration should be lazy initialized.
Must Read Spring Tool Suite
Frequently Asked Questions
What is Spring Boot Annotation?
Spring Boot Annotations are metadata that provides information about a program that isn't contained within it. They have no direct impact on the code they annotate functionality.
What is Spring Boot?
Spring Boot is a Java-based open-source framework for developing microservices. Pivotal Team created it, and it is used to create stand-alone and production-ready spring applications.
Why are annotations used in Spring Boot?
Spring Boot Annotations are a type of metadata that contains information about a particular program. Annotations, in other words, are used to provide additional information about a program.
Key Takeaways
We’ve learned about the Spring Boot Annotations and their different types in this article.
You can also check our previous blogs on STS Download, Introduction to Spring Boot, Spring Boot Auto-configuration, and Spring Boot CLI. If you are eager to learn advanced front-end web development, You can also consider our Spring Boot Course to give your career an edge over others.