Explore Courses
Liverpool Business SchoolLiverpool Business SchoolMBA by Liverpool Business School
  • 18 Months
Bestseller
Golden Gate UniversityGolden Gate UniversityMBA (Master of Business Administration)
  • 15 Months
Popular
O.P.Jindal Global UniversityO.P.Jindal Global UniversityMaster of Business Administration (MBA)
  • 12 Months
New
Birla Institute of Management Technology Birla Institute of Management Technology Post Graduate Diploma in Management (BIMTECH)
  • 24 Months
Liverpool John Moores UniversityLiverpool John Moores UniversityMS in Data Science
  • 18 Months
Popular
IIIT BangaloreIIIT BangalorePost Graduate Programme in Data Science & AI (Executive)
  • 12 Months
Bestseller
Golden Gate UniversityGolden Gate UniversityDBA in Emerging Technologies with concentration in Generative AI
  • 3 Years
upGradupGradData Science Bootcamp with AI
  • 6 Months
New
University of MarylandIIIT BangalorePost Graduate Certificate in Data Science & AI (Executive)
  • 8-8.5 Months
upGradupGradData Science Bootcamp with AI
  • 6 months
Popular
upGrad KnowledgeHutupGrad KnowledgeHutData Engineer Bootcamp
  • Self-Paced
upGradupGradCertificate Course in Business Analytics & Consulting in association with PwC India
  • 06 Months
OP Jindal Global UniversityOP Jindal Global UniversityMaster of Design in User Experience Design
  • 12 Months
Popular
WoolfWoolfMaster of Science in Computer Science
  • 18 Months
New
Jindal Global UniversityJindal Global UniversityMaster of Design in User Experience
  • 12 Months
New
Rushford, GenevaRushford Business SchoolDBA Doctorate in Technology (Computer Science)
  • 36 Months
IIIT BangaloreIIIT BangaloreCloud Computing and DevOps Program (Executive)
  • 8 Months
New
upGrad KnowledgeHutupGrad KnowledgeHutAWS Solutions Architect Certification
  • 32 Hours
upGradupGradFull Stack Software Development Bootcamp
  • 6 Months
Popular
upGradupGradUI/UX Bootcamp
  • 3 Months
upGradupGradCloud Computing Bootcamp
  • 7.5 Months
Golden Gate University Golden Gate University Doctor of Business Administration in Digital Leadership
  • 36 Months
New
Jindal Global UniversityJindal Global UniversityMaster of Design in User Experience
  • 12 Months
New
Golden Gate University Golden Gate University Doctor of Business Administration (DBA)
  • 36 Months
Bestseller
Ecole Supérieure de Gestion et Commerce International ParisEcole Supérieure de Gestion et Commerce International ParisDoctorate of Business Administration (DBA)
  • 36 Months
Rushford, GenevaRushford Business SchoolDoctorate of Business Administration (DBA)
  • 36 Months
KnowledgeHut upGradKnowledgeHut upGradSAFe® 6.0 Certified ScrumMaster (SSM) Training
  • Self-Paced
KnowledgeHut upGradKnowledgeHut upGradPMP® certification
  • Self-Paced
IIM KozhikodeIIM KozhikodeProfessional Certification in HR Management and Analytics
  • 6 Months
Bestseller
Duke CEDuke CEPost Graduate Certificate in Product Management
  • 4-8 Months
Bestseller
upGrad KnowledgeHutupGrad KnowledgeHutLeading SAFe® 6.0 Certification
  • 16 Hours
Popular
upGrad KnowledgeHutupGrad KnowledgeHutCertified ScrumMaster®(CSM) Training
  • 16 Hours
Bestseller
PwCupGrad CampusCertification Program in Financial Modelling & Analysis in association with PwC India
  • 4 Months
upGrad KnowledgeHutupGrad KnowledgeHutSAFe® 6.0 POPM Certification
  • 16 Hours
O.P.Jindal Global UniversityO.P.Jindal Global UniversityMaster of Science in Artificial Intelligence and Data Science
  • 12 Months
Bestseller
Liverpool John Moores University Liverpool John Moores University MS in Machine Learning & AI
  • 18 Months
Popular
Golden Gate UniversityGolden Gate UniversityDBA in Emerging Technologies with concentration in Generative AI
  • 3 Years
IIIT BangaloreIIIT BangaloreExecutive Post Graduate Programme in Machine Learning & AI
  • 13 Months
Bestseller
IIITBIIITBExecutive Program in Generative AI for Leaders
  • 4 Months
upGradupGradAdvanced Certificate Program in GenerativeAI
  • 4 Months
New
IIIT BangaloreIIIT BangalorePost Graduate Certificate in Machine Learning & Deep Learning (Executive)
  • 8 Months
Bestseller
Jindal Global UniversityJindal Global UniversityMaster of Design in User Experience
  • 12 Months
New
Liverpool Business SchoolLiverpool Business SchoolMBA with Marketing Concentration
  • 18 Months
Bestseller
Golden Gate UniversityGolden Gate UniversityMBA with Marketing Concentration
  • 15 Months
Popular
MICAMICAAdvanced Certificate in Digital Marketing and Communication
  • 6 Months
Bestseller
MICAMICAAdvanced Certificate in Brand Communication Management
  • 5 Months
Popular
upGradupGradDigital Marketing Accelerator Program
  • 05 Months
Jindal Global Law SchoolJindal Global Law SchoolLL.M. in Corporate & Financial Law
  • 12 Months
Bestseller
Jindal Global Law SchoolJindal Global Law SchoolLL.M. in AI and Emerging Technologies (Blended Learning Program)
  • 12 Months
Jindal Global Law SchoolJindal Global Law SchoolLL.M. in Intellectual Property & Technology Law
  • 12 Months
Jindal Global Law SchoolJindal Global Law SchoolLL.M. in Dispute Resolution
  • 12 Months
upGradupGradContract Law Certificate Program
  • Self paced
New
ESGCI, ParisESGCI, ParisDoctorate of Business Administration (DBA) from ESGCI, Paris
  • 36 Months
Golden Gate University Golden Gate University Doctor of Business Administration From Golden Gate University, San Francisco
  • 36 Months
Rushford Business SchoolRushford Business SchoolDoctor of Business Administration from Rushford Business School, Switzerland)
  • 36 Months
Edgewood CollegeEdgewood CollegeDoctorate of Business Administration from Edgewood College
  • 24 Months
Golden Gate UniversityGolden Gate UniversityDBA in Emerging Technologies with Concentration in Generative AI
  • 36 Months
Golden Gate University Golden Gate University DBA in Digital Leadership from Golden Gate University, San Francisco
  • 36 Months
Liverpool Business SchoolLiverpool Business SchoolMBA by Liverpool Business School
  • 18 Months
Bestseller
Golden Gate UniversityGolden Gate UniversityMBA (Master of Business Administration)
  • 15 Months
Popular
O.P.Jindal Global UniversityO.P.Jindal Global UniversityMaster of Business Administration (MBA)
  • 12 Months
New
Deakin Business School and Institute of Management Technology, GhaziabadDeakin Business School and IMT, GhaziabadMBA (Master of Business Administration)
  • 12 Months
Liverpool John Moores UniversityLiverpool John Moores UniversityMS in Data Science
  • 18 Months
Bestseller
O.P.Jindal Global UniversityO.P.Jindal Global UniversityMaster of Science in Artificial Intelligence and Data Science
  • 12 Months
Bestseller
IIIT BangaloreIIIT BangalorePost Graduate Programme in Data Science (Executive)
  • 12 Months
Bestseller
O.P.Jindal Global UniversityO.P.Jindal Global UniversityO.P.Jindal Global University
  • 12 Months
WoolfWoolfMaster of Science in Computer Science
  • 18 Months
New
Liverpool John Moores University Liverpool John Moores University MS in Machine Learning & AI
  • 18 Months
Popular
Golden Gate UniversityGolden Gate UniversityDBA in Emerging Technologies with concentration in Generative AI
  • 3 Years
Rushford, GenevaRushford Business SchoolDoctorate of Business Administration (AI/ML)
  • 36 Months
Ecole Supérieure de Gestion et Commerce International ParisEcole Supérieure de Gestion et Commerce International ParisDBA Specialisation in AI & ML
  • 36 Months
Golden Gate University Golden Gate University Doctor of Business Administration (DBA)
  • 36 Months
Bestseller
Ecole Supérieure de Gestion et Commerce International ParisEcole Supérieure de Gestion et Commerce International ParisDoctorate of Business Administration (DBA)
  • 36 Months
Rushford, GenevaRushford Business SchoolDoctorate of Business Administration (DBA)
  • 36 Months
Liverpool Business SchoolLiverpool Business SchoolMBA with Marketing Concentration
  • 18 Months
Bestseller
Golden Gate UniversityGolden Gate UniversityMBA with Marketing Concentration
  • 15 Months
Popular
Jindal Global Law SchoolJindal Global Law SchoolLL.M. in Corporate & Financial Law
  • 12 Months
Bestseller
Jindal Global Law SchoolJindal Global Law SchoolLL.M. in Intellectual Property & Technology Law
  • 12 Months
Jindal Global Law SchoolJindal Global Law SchoolLL.M. in Dispute Resolution
  • 12 Months
IIITBIIITBExecutive Program in Generative AI for Leaders
  • 4 Months
New
IIIT BangaloreIIIT BangaloreExecutive Post Graduate Programme in Machine Learning & AI
  • 13 Months
Bestseller
upGradupGradData Science Bootcamp with AI
  • 6 Months
New
upGradupGradAdvanced Certificate Program in GenerativeAI
  • 4 Months
New
KnowledgeHut upGradKnowledgeHut upGradSAFe® 6.0 Certified ScrumMaster (SSM) Training
  • Self-Paced
upGrad KnowledgeHutupGrad KnowledgeHutCertified ScrumMaster®(CSM) Training
  • 16 Hours
upGrad KnowledgeHutupGrad KnowledgeHutLeading SAFe® 6.0 Certification
  • 16 Hours
KnowledgeHut upGradKnowledgeHut upGradPMP® certification
  • Self-Paced
upGrad KnowledgeHutupGrad KnowledgeHutAWS Solutions Architect Certification
  • 32 Hours
upGrad KnowledgeHutupGrad KnowledgeHutAzure Administrator Certification (AZ-104)
  • 24 Hours
KnowledgeHut upGradKnowledgeHut upGradAWS Cloud Practioner Essentials Certification
  • 1 Week
KnowledgeHut upGradKnowledgeHut upGradAzure Data Engineering Training (DP-203)
  • 1 Week
MICAMICAAdvanced Certificate in Digital Marketing and Communication
  • 6 Months
Bestseller
MICAMICAAdvanced Certificate in Brand Communication Management
  • 5 Months
Popular
IIM KozhikodeIIM KozhikodeProfessional Certification in HR Management and Analytics
  • 6 Months
Bestseller
Duke CEDuke CEPost Graduate Certificate in Product Management
  • 4-8 Months
Bestseller
Loyola Institute of Business Administration (LIBA)Loyola Institute of Business Administration (LIBA)Executive PG Programme in Human Resource Management
  • 11 Months
Popular
Goa Institute of ManagementGoa Institute of ManagementExecutive PG Program in Healthcare Management
  • 11 Months
IMT GhaziabadIMT GhaziabadAdvanced General Management Program
  • 11 Months
Golden Gate UniversityGolden Gate UniversityProfessional Certificate in Global Business Management
  • 6-8 Months
upGradupGradContract Law Certificate Program
  • Self paced
New
IU, GermanyIU, GermanyMaster of Business Administration (90 ECTS)
  • 18 Months
Bestseller
IU, GermanyIU, GermanyMaster in International Management (120 ECTS)
  • 24 Months
Popular
IU, GermanyIU, GermanyB.Sc. Computer Science (180 ECTS)
  • 36 Months
Clark UniversityClark UniversityMaster of Business Administration
  • 23 Months
New
Golden Gate UniversityGolden Gate UniversityMaster of Business Administration
  • 20 Months
Clark University, USClark University, USMS in Project Management
  • 20 Months
New
Edgewood CollegeEdgewood CollegeMaster of Business Administration
  • 23 Months
The American Business SchoolThe American Business SchoolMBA with specialization
  • 23 Months
New
Aivancity ParisAivancity ParisMSc Artificial Intelligence Engineering
  • 24 Months
Aivancity ParisAivancity ParisMSc Data Engineering
  • 24 Months
The American Business SchoolThe American Business SchoolMBA with specialization
  • 23 Months
New
Aivancity ParisAivancity ParisMSc Artificial Intelligence Engineering
  • 24 Months
Aivancity ParisAivancity ParisMSc Data Engineering
  • 24 Months
upGradupGradData Science Bootcamp with AI
  • 6 Months
Popular
upGrad KnowledgeHutupGrad KnowledgeHutData Engineer Bootcamp
  • Self-Paced
upGradupGradFull Stack Software Development Bootcamp
  • 6 Months
Bestseller
KnowledgeHut upGradKnowledgeHut upGradBackend Development Bootcamp
  • Self-Paced
upGradupGradUI/UX Bootcamp
  • 3 Months
upGradupGradCloud Computing Bootcamp
  • 7.5 Months
PwCupGrad CampusCertification Program in Financial Modelling & Analysis in association with PwC India
  • 5 Months
upGrad KnowledgeHutupGrad KnowledgeHutSAFe® 6.0 POPM Certification
  • 16 Hours
upGradupGradDigital Marketing Accelerator Program
  • 05 Months
upGradupGradAdvanced Certificate Program in GenerativeAI
  • 4 Months
New
upGradupGradData Science Bootcamp with AI
  • 6 Months
Popular
upGradupGradFull Stack Software Development Bootcamp
  • 6 Months
Bestseller
upGradupGradUI/UX Bootcamp
  • 3 Months
PwCupGrad CampusCertification Program in Financial Modelling & Analysis in association with PwC India
  • 4 Months
upGradupGradCertificate Course in Business Analytics & Consulting in association with PwC India
  • 06 Months
upGradupGradDigital Marketing Accelerator Program
  • 05 Months

Spring Boot Basic Annotations Everyone Should Know

Updated on 06 October, 2022

5.79K+ views
7 min read

Java Spring Framework is an open-source and enterprise-level framework used to create production-grade, standalone applications that run on the Java Virtual Machine (JVM). To this end, Java Spring Boot is a tool that simplifies and accelerates the development of web applications and microservices with the Spring Framework. For this, Java Spring Boot leverages three core capabilities – autoconfiguration, an opinionated approach to configuration, and the potential to create standalone applications. The amalgamation of these core features provides a tool that allows developers to set up Spring-based applications with minimal configurations.

Before annotations, the Spring Framework behavior was mostly XML configuration-controlled. However, Spring Boot annotations have dramatically altered how you can configure the behaviors of the Spring Framework. 

In this article, we’ll go through some of the basic annotations in the Spring Framework.

What Are Spring Boot Annotations?

Spring Boot annotations are a form of metadata. They are not a part of the application under development per se but provide supplemental data about a program. Annotations have no direct impact on the operation of the code they annotate, nor do they alter the action of the compiled program. 

Spring applications require a significant degree of configuration. Spring Boot is an opinionated framework that builds off the Spring Framework. It minimizes the configuration efforts and boilerplate one needs to get started. Spring Boot annotations are the key to gaining control over the Spring Framework, directing the framework, and overriding its defaults when required. These annotations are easy to use and quicker than building the equivalent functionalities from scratch. 

Spring Boot Annotations Everyone Should Know

Although Spring Boot works Java, Groovy, and Kotlin, we’ll focus on Java while discussing the important Spring Boot annotations.

1. @Configuration

The @Configuration is used in classes that define beans. An analog of XML configuration file is a class-level annotation used as a source of bean definitions. A @Configuration annotated Java class is a configuration in itself and has methods to configure and instantiate dependencies. 

Example:

@Configuration
public class Bus
{
@BeanBus engine()
{
return new Bus();
}
}

2. @Bean

An alternative to the XML <bean> tag, the @Bean annotation is used at the method level to indicate that a method produces a bean to be managed by the Spring container. This annotation works along with @Configuration to create Spring beans. The @Configuration has methods to configure and instantiate dependencies, and such methods are annotated by @Bean. 

Example:

@Bean
Public BeanExample beanExample ()
{
return new BeanExample (),
}

3. @ComponentScan

The @ComponentScan annotation is used to scan a package of beans. It is used along with the @Configuration annotation to let Spring know the packages that must be scanned for annotated components. 

Example:

@ComponentScan(basePackages = “com.xyz”)
@Configuration
Public class ScanComponent
{
//…
}

4. @Component

The @Component annotation is used on classes to denote a Spring component. It is a class-level annotation that converts the class into Spring bean during auto-scan.

Example:

@Component
Public class Teachers
{
……
}

5. @EnableAutoConfiguration

The @EnableAutoConfiguration annotation is typically placed on the main application class, and it implicitly defines a base search package. Based on classpath settings, various property settings, and other beans, @EnableAutoConfiguration directs Spring Boot to begin adding beans. 

6. @SpringBootApplication  

The @SpringBootApplication annotation adds three annotations – @Configuration, @EnableAutoConfiguration, and @ComponentScan. It is used on the application class while setting up the Spring Boot project, and the class annotated with @SpringBootApplication is placed in the base package. The @SpringBootApplication does component scanning, but only of the sub-packages. 

7. @Repository 

The @Repository annotation is used on Java classes that access the database directly. It works as a marker for classes that fulfill the role of Data Access Object or repository. 

Example:

@Repository
public class TestRepository
{
public void delete()
{
// persistence code
}
}

8. @Service 

It is a class-level annotation that marks a Java class performing a service such as executing business logic, performing calculations, or calling external APIs. A @Service annotation is a special form of the @Component annotation for use in the service layer.

Example:

@Service
public class TestService
{
public void service1()
{
// business code
}
}

9. @Autowired

This annotation implicitly injects object dependency and is applied on fields, constructors, and setter methods. When @Autowired is used on fields, and the values for the fields are passed using the property name, Spring automatically assigns the fields with the passed values. 

10. @Controller

The @Controller annotation is used on Java classes that serve as the controller in an application. It allows auto-detecting component classes in the classpath and also auto-registers of bean definitions for them. The @Controller annotation is typically used with @RequestMapping, and the Java classes annotated with @Controller can handle multiple request mappings. 

Example:

@Controller
@RequestMapping(“cars”)
public class CarsController
{
@RequestMapping(value= “/{name}”, method= RequestMethod.GET)
public Employee getCarsByName()
{
Return carsTemplate;
}
}

11. @RequestMapping

The @RequestMapping annotation is used at both the method and class level. It serves to map web requests onto specified handler methods and handler classes. When @RequestMapping is used on methods, it gives the URL on which handler methods execution will occur. On the contrary, when the annotation is used at the level of classes, it creates a base URL for which the controller will be used. Hence, each handler method will have its respective request mapping, whereas the class-level request mapping remains the same.

Example:

@Controller
public class FlowersController
{
@RequestMapping (“/red-colour/flowers”)
public String getAllFlowers(Model model)
{
//application code
return “flowerlist”;
}

12. @Qualifier 

@Qualifier is used along with @Autowired when more control is needed over the dependency injection process. The @Qualifier annotation may be specified either on method parameters or individual constructor arguments. Confusions usually arise when the developer creates more than one bean of the same type, but only one of them has to be wired with a property. The @Qualifier annotation comes in handy to eliminate these confusions.

Example:

@Component

public class BeanB1 implements BeanInterface {
  //
}
@Component
public class BeanB2 implements BeanInterface {
  //
}
In the above example, BeanInterface is implemented by the two beans BeanB1 and BeanB2. Now, if BeanA autowires this interface, Spring wouldn’t know which of the two implementations it should inject. You can solve this problem using the @Qualifier annotation. With this annotation in place, Spring will know which of the beans to autowire. 
@Component
public class BeanA {
  @Autowired
  @Qualifier(“beanB2”)
  private BeanInterface dependency;
  …
}

13. @Value

The @Value annotation is used at the field, method parameter, and constructor parameter levels. It denotes a default value expression for the parameter or field to initialize the property with.

14. @Lazy  

The @Lazy annotation is applied to the component classes. At startup, all autowired dependencies are created and configured by default. But the @Lazy annotation can be used if the developer wants to initialize a bean lazily. Thus, the bean gets created and initialized only upon request. The @Lazy annotation can also be used on @Configuration classes, which means that all @Bean methods in that @Configuration will be initiated lazily.

While this list of Java Spring Boot annotations is not exhaustive, it more or less covers the most basic ones that every developer or Java enthusiast should know. After all, Spring Boot has simplified the development of Spring-based applications and is worth knowing. 

Master of Science in Data Science from Liverpool John Moores University

If you are an aspiring data scientist, here’s an opportunity to learn from the best. upGrad offers an online Master of Science in Data Science in partnership with Liverpool John Moores University, specially designed for working professionals looking to hone their data science skills and knowledge. 

Here are some program highlights at a glance:

  • Master’s Degree from LJMU and Executive PGP from IIT Bangalore
  • 500+ hours of learning packed with live sessions, case studies, and projects
  • Comprehensive coverage of 14+ tools and software
  • Three unique specializations
  • 360-degree dedicated career assistance 
  • Peer learning and industry networking

upGrad’s immersive and industry-relevant learning programs have impacted over 500,000 working professionals globally and continue to set high standards in the higher EdTech industry. So, apply today and join the 40,000+ global learner base spread over 85 countries!

Learn data science courses online from the World’s top Universities. Earn Executive PG Programs, Advanced Certificate Programs, or Masters Programs to fast-track your career.

Frequently Asked Questions (FAQs)

1. What is the purpose of the Spring Boot starter?

Spring Boot starters are dependency descriptors that allow adding jars in the classpath. Every starter has the following naming pattern in the Spring Boot framework: spring-boot-starter-*, where the * represents a particular application type.

2. What is the difference between @SpringBootApplication and @EnableAutoConfiguration?

The primary task of @EnableAutoConfiguration is to enable the automatic configuration features of the Spring Boot application. On the contrary, @SpringBootApplication combines three annotations - @ComponentScan for component scanning, @Configuration for Java-based configuration on Spring framework, and @EnableAutoConfiguration for allowing automatic configuration in Spring Boot applications.

3. Can Spring boot run without SpringBootApplication?

It is not compulsory to use @SpringBootApplication to create a Spring Boot application. You can still use @EnableAutoConfiguration and @Configuration individually.