Skip to content
  • Facebook
GeekCer Logo

GeekCer

The geek's Coding education and Review centre

  • Home
  • Tutorials
    • Java
    • Servlet
    • JSP
    • Python
    • C Tutorial
    • Spring
    • Spring Boot
    • MongoDB
    • Hibernate
    • Data Structure
  • General Knowledge
  • Biography
  • Grammar
  • Festival (त्योहार)
  • Interview
  • Differences
  • Important
  • Toggle search form

Home » Spring Boot » Top Spring Boot Annotations

  • Mahatma Gandhi Essay in Hindi | Gandhiji Biography
    Mahatma Gandhi Essay in Hindi | Gandhiji Biography Biography
  • Diwali The Festival of Lights
    Diwali 2022, Indian Festival of Lights essay (दिवाली त्योहार पर निबंध, कहानी) Festival
  • Human rights day
    Human rights day in Hindi: 10 दिसंबर ह्यूमन राइट्स डे General Knowledge
  • Kishkindha Kand in Hindi | Ram meets Hanuman | किष्किंधा कांड
    Kishkindha Kand in Hindi | Ram meets Hanuman | किष्किंधा कांड Spiritual
  • MS Dhoni (Mahendra singh Dhoni) Cricket Biography in Hindi
    MS Dhoni (Mahendra singh Dhoni) Cricket Biography in Hindi Biography
  • What is Adjective in Hindi (विशेषण क्या है?)
    What is Adjective in Hindi (विशेषण क्या है?) Grammar
  • Fundamental Rights of Indian Citizens
    Fundamental Rights of Indian Citizens | मौलिक अधिकार क्या हैं? General Knowledge
  • International Nurses Day in Hindi | नर्स दिवस क्यों मनाते हैं?
    International Nurses Day in Hindi | नर्स दिवस क्यों मनाते हैं? General Knowledge

Top Spring Boot Annotations

Posted on October 19, 2021January 30, 2022 By GeekCer Education No Comments on Top Spring Boot Annotations
Top Spring Boot Annotations

Spring Boot annotations are meant to simplify configuration and eliminate XML configurations which are complex as compared to annotations.

When we read Spring, we see that the configuration that took place there can be done in a variety of ways. The configuration in the previous Spring version was based on XML. To configure the system, we used to work in the XML file. We used to make an xml file, and we had to define beans there. The style of configuration changed when new versions were released, such as Java-based configuration and annotation-based configuration come there.
We don’t have to put much work into annotation-based configuration, and we don’t have to create a separate xml file.

Annotations may be used to configure the spring framework in its newest version. As a result, it is recommended that you use Java or Annotation-based setup.

The majority of the annotations come from the Spring Framework. However, the example we’ll provide will be used in Spring Boot. These annotations are applicable to both.

Table of Contents

  • List of Spring Boot Annotations
    • @SpringBootApplication
    • @Bean
    • @Component
    • @Autowired
    • @EnableAutoConfiguration
    • @ComponentScan
    • @Qualifier

List of Spring Boot Annotations

There are several spring boot annotations available, which are listed below.

@SpringBootApplication

@SpringBootApplication is responsible for auto configuration. If we use this annotation the components are scanned and configured.

@SpringBootApplication is equivalent to the @Configuration, @ComponentScan and @EnableAutoConfiguration annotations. @SpringBootApplication is used at the class level and this annotation is placed in the base package.

The main class of the Spring Boot application is the Java class annotated with @SpringBootApplication, and it is from here that the application starts.

                  package com.geekcer.app;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

// Same as @Configuration @EnableAutoConfiguration @ComponentScan
@SpringBootApplication 
public class Application {

  public static void main(String[] args) {
   SpringApplication.run(Application.class, args);
  }
}

@Bean

@Bean annotation is method level annotation. If we use this annotation then method should returns a bean that the Spring container manages that bean.

public class BeanExample {

   @Bean
   public Employee getEmployee() {
      return new Employee();
   }
}

@Component

Whenever we use @Component annotation, we are specifying that this component will be managed by Spring. Spring will be in control of this class object. Because it is a component of a spring.

This is an annotation at the class level. It’s used to indicate that a class is a bean. When we annotate a class with @component, it becomes available in the class path, where it is picked up by the spring framework, which configures the application environment and starts utilizing it as a spring bean.

@Component
public class Employee {
 .....
}

@Autowired

The Spring bean is autowired using the @Autowired annotation. It can be used with constructors, setter methods and instance variables.

It implicitly injects object dependencies. The Spring container auto-wires the bean with its matching data type when we use this annotation.

public class Emplyee {

    @Autowired                               
    private Department dept;  
	
    private String empName;
}

@EnableAutoConfiguration

Auto configuration is enabled when @EnableAutoConfiguration is specified. Spring Boot will now start inserting beans as a result of this annotation. These instructions are based on the class path, other beans and other property settings.

@EnableAutoConfiguration annotation is used in the application’s main class.

@Configuration
@EnableAutoConfiguration
public class GeekApplicationConfig {
...
}

How to disable a specific auto-configuration class? To exclude/disable a certain class, we may utilize the @EnableAutoConfiguration annotation’s exclude property.

@Configuration
// Use of exclude
@EnableAutoConfiguration(exclude ={classname})
public class GeekApplicationConfig {
...
}

@ComponentScan

The @ComponentScan annotation is used to scan a package. It’s used in combination with @configuration. We can also specify the package in @ComponentScan.

@Configuration
@ComponentScan(basePackages = "com.geekcer")
public class Department {
 .....
}

@Qualifier

When using the @Bean annotation and creating many beans of the same type, there may be some confusion when autowiring which bean to use.

The @Qualifier annotation is used to eliminate this confusion. We give each bean a tag/name using the @Qualifier, and we also use @Autowire with that tag/name.

Click here to to learn the scopes of the bean.

Share this:

  • Click to share on Facebook (Opens in new window)
  • Click to share on WhatsApp (Opens in new window)
  • Click to share on Twitter (Opens in new window)
  • More
  • Click to share on LinkedIn (Opens in new window)
  • Click to share on Pinterest (Opens in new window)

Also Read

Spring Boot

Post navigation

Previous Post: Spring Initializr for Spring Boot Project
Next Post: Bean Scopes in Spring, Types of Bean Scopes, Examples

More Related Articles

Spring Boot Tutorial Spring Boot Tutorial Spring Boot
Mockito unit testing spring boot Mockito Framework Tutorial for Unit testing | Mockito unit testing spring boot Important
HTTP status codes List | Response Status Code Glossary HTTP status codes List | Response Status Code Glossary Important
Bean Scopes in Spring, Types of Bean Scopes, Examples Bean Scopes in Spring, Types of Bean Scopes, Examples Spring
Spring Initializr for Spring Boot Project Spring Initializr for Spring Boot Project Spring Boot

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

  • National Farmers Day in Hindi | राष्ट्रीय किसान दिवस पर निबंध | चौधरी चरण सिंह जयंती
  • Human rights day in Hindi: 10 दिसंबर ह्यूमन राइट्स डे
  • Unicef day is celebrated on December 11 | Speech on unicef day
  • Indian Navy Day: जल सेना दिवस कब और क्यों मनाया जाता है?
  • P V Sindhu Biography in Hindi, Badminton, State, Caste पी. वी. सिंधु जीवन परिचय, कहानी, राज्य, जाति
  • Draupadi Murmu Biography In Hindi | द्रौपदी मुर्मू की जीवनी
  • Similarities and difference between OSI and TCP/IP model
    OSI vs TCP/IP Model, Similarities and difference between OSI and TCP/IP model Networking
  • Network kya hai (नेटवर्क क्या है)
    Network kya hai (नेटवर्क क्या है) Networking
  • OSI Model | 7 Layers of OSI Model in Computer network
    OSI Model | 7 Layers of OSI Model in Computer network, Functions Networking
  • Difference between Internet and Intranet
    Difference between Internet and Intranet Differences
  • TCP/IP Model, Full Form, Layers and their Functions
    TCP/IP Model, Full Form, Layers and their Functions Networking
  • IPv4 Vs IPv6 | Difference between IPv4 and IPv6
    IPv4 Vs IPv6 | Difference between IPv4 and IPv6 Differences
  • Difference between TCP and UDP
    Difference between TCP and UDP | TCP vs UDP examples Differences
  • Java Tutorial
  • Servlet Tutorial
  • JSP Tutorial
  • Maven Tutorial
  • HTML Tutorial
  • Programs
  • Hindi/English Grammar
  • Difference Between ... and ...
  • HR Interview
  • Important Articles

Write to Us:
geekcer.code@gmail.com

  • About Us
  • Privacy and Policy
  • Disclaimer
  • Contact Us
  • Sitemap

Copyright © GeekCer 2022 All Rights reserved