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

  • What is Adjective in Hindi (विशेषण क्या है?)
    What is Adjective in Hindi (विशेषण क्या है?) Grammar
  • Difference between SQL and HQL
    Difference between SQL and HQL | Hql vs Sql performance Differences
  • What is Computer
    What is Computer? Important
  • Spring Initializr for Spring Boot Project
    Spring Initializr for Spring Boot Project Spring Boot
  • Christmas Day Celebration
    Christmas Day Celebration (क्रिसमस दिवस क्यों मनाते हैं?) Festival
  • Software Performance Testing in Hindi
    Software Performance Testing in Hindi Important
  • Sawan ka Mahina : सावन का महीना का महत्व, भगवान शिव की पूजा
    Sawan ka Mahina : सावन का महीना का महत्व, भगवान शिव की पूजा Festival
  • Learn MongoDB Tutorial, Installation, MongoDB DataTypes
    Learn MongoDB Tutorial, Installation, MongoDB DataTypes MongoDB

Top Spring Boot Annotations

Posted on October 19, 2021January 30, 2022 By admin 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 Initializr for Spring Boot Project Spring Initializr for Spring Boot Project Spring Boot
Bean Scopes in Spring, Types of Bean Scopes, Examples Bean Scopes in Spring, Types of Bean Scopes, Examples Spring
HTTP status codes List | Response Status Code Glossary HTTP status codes List | Response Status Code Glossary Important
Spring Boot Tutorial Spring Boot Tutorial Spring Boot

Related Posts

  • Spring Initializr for Spring Boot Project
    Spring Initializr for Spring Boot Project Spring Boot
  • Bean Scopes in Spring, Types of Bean Scopes, Examples
    Bean Scopes in Spring, Types of Bean Scopes, Examples Spring
  • HTTP status codes List | Response Status Code Glossary
    HTTP status codes List | Response Status Code Glossary Important
  • Spring Boot Tutorial
    Spring Boot Tutorial Spring Boot

Leave a Reply Cancel reply

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

Recent Posts

  • Structured Vs Unstructured Data in Hindi | Key Difference
  • Jhansi Ki Rani Lakshmi Bai History, Story, Information in Hindi
  • Elon musk Hindi : एलन मस्क हिंदी में, Autobiography,  Net Worth
  • World Environment Day in Hindi : Objective, Importance, Theme
  • Thomas Edison Biography in Hindi – थॉमस एडिसन जीवनी
  • International Nurses Day in Hindi | नर्स दिवस क्यों मनाते हैं?
  • Fork/Join Framework in Java | RecursiveTask, RecursiveAction
  • DBMS in Hindi | DBMS क्या है? | DBMS की विशेषताएं और प्रकार
  • What is Adjective in Hindi (विशेषण क्या है?)
    What is Adjective in Hindi (विशेषण क्या है?) Grammar
  • Difference between SQL and HQL
    Difference between SQL and HQL | Hql vs Sql performance Differences
  • What is Computer
    What is Computer? Important
  • Spring Initializr for Spring Boot Project
    Spring Initializr for Spring Boot Project Spring Boot
  • Christmas Day Celebration
    Christmas Day Celebration (क्रिसमस दिवस क्यों मनाते हैं?) Festival
  • Software Performance Testing in Hindi
    Software Performance Testing in Hindi Important
  • Sawan ka Mahina : सावन का महीना का महत्व, भगवान शिव की पूजा
    Sawan ka Mahina : सावन का महीना का महत्व, भगवान शिव की पूजा Festival
  • Learn MongoDB Tutorial, Installation, MongoDB DataTypes
    Learn MongoDB Tutorial, Installation, MongoDB DataTypes MongoDB
  • 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