Main Method | Spring Boot Bootstrapping

Learn via video courses
Topics Covered

Overview

As spring boot application creates an executable JAR with all the dependencies built in. Therefore there should be an entry point into the jar for it to execute. Spring boot provides entry into the application using the main method.

Transform Your Career

Choose from our industry-leading programs designed for career success

NSDC Certified

Modern Software and AI Engineering Program

Master full-stack development with AI integration

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

Modern Data Science and ML with specialisation in AI

Advanced data science techniques with AI specialization

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

Advanced AIML with Specialisation in Agentic AI

Deep dive into AIML with focus on Agentic systems

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

DevOps, Cloud & AI Platform Engineering

Build and manage AI-powered cloud infrastructure

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

AI Engineering Advanced Certification by IIT-Roorkee

Premier AI engineering certification from IIT-Roorkee

3 MonthsDuration
AI-LedCurriculum
Career SupportSupport
Program highlights
Go to Program

What is the @SpringBootApplication

If we decompile the source of this annotation, we can see the following snippets.

@SpringBootApplication is a combination of the following three annotations.

  • @SpringBootConfiguration
  • @EnableAutoConfiguration
  • @ComponentScan

@SpringBootConfiguration

This annotation is the same as the @Configuration annotation. It designates the class as a configuration class.

Free Courses by top Scaler instructors
Python Course for Beginners With Certification: Mastering the Essentials
Java Course - Mastering the Fundamentals
DBMS Course - Master the Fundamentals and Advanced Concepts
JavaScript Course With Certification: Unlocking the Power of JavaScript
C++ Course: Learn the Essentials
Python and SQL for Data Science
Python Course for Beginners With Certification: Mastering the Essentials
Java Course - Mastering the Fundamentals
DBMS Course - Master the Fundamentals and Advanced Concepts
JavaScript Course With Certification: Unlocking the Power of JavaScript
C++ Course: Learn the Essentials
Python and SQL for Data Science

@ComponentScan

This annotation enables component scanning. Any bean available in the classpath will be scanned by the Spring Framework and registered in the IoC container. For example, classes marked with @Component, @RestController, and @Service will be registered with the Spring IoC container.

Scaler Placement Report and Statistics

₹23L
AVG CTC
SCALER PLACEMENT PROOF

Scaler learners achieved 2.5x salary growth with average post-Scaler CTC reaching ₹23L.

11,000+placements
650+companies
Verified data
Hiring Partners:
GoogleGoogleAmazonAmazonMicrosoftMicrosoftFlipkartFlipkartAdobeAdobe1200+ more

@EnableAutoConfiguration

This annotation enables the magical auto-configuration feature of Spring Boot. Without this annotation, spring boot loses its power, and the framework needs to be configured by developers for everything like dispatcher servlet, entity factory, etc.

If you individually replace @SpringBootApplicaiton with the above three annotations, the effect will be the same. @SpringBootApplication annotation is provided only for developer convenience. It does not have any special logic tagged to it.

Parameters Accepted in the @SpringBootApplication annotation

SpringBootApplication annotation accepts parameters to customize the application. Parameters are allies for individual annotation. A few key parameters are:

Turn Learning into Career Growth

1200+Hiring Partners
89%Placement Rate
11,000+Placements
147%Avg Salary Increment
2.5XCareer Growth
₹23 LPAAvg Post-Scaler Salary
1200+Hiring Partners
89%Placement Rate
11,000+Placements
147%Avg Salary Increment
2.5XCareer Growth
₹23 LPAAvg Post-Scaler Salary

exclude()

This parameter allows developers to exclude specific auto-configurations. For example, if you don't want the framework-configured data source, then the required exclusion should be supplied to the parameter.

OR

scanBasePackages()

By default, spring boot scans the current package and all the child packages for spring beans. This parameter allows developers to override default scan behavior. We can specify what packages our application should specifically scan for the spring beans.

OR

What is the Role of @SpringBootApplication Annotation?

The Class with the main method in spring boot must be annotated with the @SpringBootApplication annotation. It's a bootstrap class for any spring boot application, and this annotation during the bootstrapping adds all the framework capabilities like enabling autoconfiguration, scanning packages for spring beans, etc.

Conclusion

  • @SpringBootApplication is a stereotype annotation.
  • Class with main method must be annotated with @SpringBootApplication annotation.
  • @SpringBootApplication annotation comprises three individual annotations. This annotation is provided for developer convenience.
  • main method and @SpringBootApplication provided entry points in the bootable jar and bootstrap the application.