SpringBootApplication annotation in springboot
Posted By : Gaurav Kumar | 14-Dec-2020
Hi, folks hope I found you well and healthy in these tough times. In this quick blog i am sharing the implementation behing the @SpringBootApplication annotation. Basically if you get a fresh skeleton of spring boot project from any one of mentioned below:
- Spring Initializer (https://start.spring.io/)
- Spring Starter project.
- Spring CLI
What ever way you had picked you got a default main method annotated with @SpringBootApplication . It means, it will added three different annotations i.e. @Configuration, @ComponentScan and @EnableAutoConfiguration at once by just using one annotation @SpringBootApplication. Ofcourse, spring boot added their default configuration here.
Also Read: Spring Boot Application With Zull API Gateway
Let's dig deep into implementation to see actual code inside @SpringBootApplication annotation. Here, is a snap shot of @SpringBootApplication interface taken from source code.
The overall idea is to make things easier for production based development in spring boot that's what this whole spring boot frame work al about, actually the framework is implementing the same stuff on behalf of develeoper and letting developer to focuses on convention over configuration. In spring boot starter project (any one of mentioned above) does the same stuff, they created a small spring application with all the required basic dependencies and mapped those with newly created skeleton, and made ourself free to configure all those xml based or java based configuration to make a simple Hello world applilcation.
Also Read: Working on IOT With Spring Boot Using MQTT
You can see it is basically calling the @EnableAutoConfiguration and @ComponentScan annotation implicitly, and @SpringBootConfiguration annotation implicitly annotated with @Configuration annotation.
Rapid short over view of all three annotatioins:
@Configuration : This annotation marks a class as a Configuration class for Java-based configuration. If you are inclined more towards Java-based configuration than XML configuration, it is important.
@ComponentScan : This annotation enables component-scanning. When you use this annotation, the web controller classes and other components you create will be automatically discovered and registered as beans in Spring's Application Context. All the@Controller classes you write are discovered by this annotation and ready for autowiring.
@EnableAutoConfiguration : This annotation enables the magical auto-configuration feature of Spring Boot, which can automatically configure a lot of stuff for you.
Explore more on this on Spring official website
Hope you find this quick blog informative. Thanks for your time.
We, at Oodles Technologies, provide full-scale SaaS app development services to build scalable, responsive, and quality-driven web and mobile applications. Contact us for technical assistance or drop us a line at [email protected] for more detail.
References :Spring.io
Cookies are important to the proper functioning of a site. To improve your experience, we use cookies to remember log-in details and provide secure log-in, collect statistics to optimize site functionality, and deliver content tailored to your interests. Click Agree and Proceed to accept cookies and go directly to the site or click on View Cookie Settings to see detailed descriptions of the types of cookies and choose whether to accept certain cookies while on the site.
About Author
Gaurav Kumar
He is always ready to grasp new tech and tools as per project requirement.