DEV Community


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.


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) {, args);

Enter fullscreen mode Exit fullscreen mode

Top comments (0)

Here is a post you might want to check out:

Regex for lazy developers

regex for lazy devs

Sorry for the callout 😆