DEV Community

Tommy
Tommy

Posted on

What's @SpringBootApplication Annotation?

In a nutshell, @SpringBootApplication is a convenience annotation that is equivalent to declaring three separate annotations @Configuration, @EnableAutoConfiguration, and @ComponentScan with their default attributes. It is typically used on the main class of a Spring Boot application to enable auto-configuration, component scanning, and to define the application context.

  • @Configuration: Indicates that the class is a source of bean definitions for the application context.

  • @EnableAutoConfiguration: Enables Spring Boot's auto-configuration mechanism, which automatically configures the application based on the dependencies that are added in the classpath.

  • @ComponentScan: Enables component scanning so that the annotated components are automatically discovered and registered as beans in the application context.

By using the @SpringBootApplication annotation, developers can write less code and make their code easier to read and understand.

ex:

package com.example.myapplication;

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

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

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

}
Enter fullscreen mode Exit fullscreen mode

Top comments (0)

An Animated Guide to Node.js Event Loop

Node.js doesn’t stop from running other operations because of Libuv, a C++ library responsible for the event loop and asynchronously handling tasks such as network requests, DNS resolution, file system operations, data encryption, etc.

What happens under the hood when Node.js works on tasks such as database queries? We will explore it by following this piece of code step by step.