@SpringBootApplication
AnnotationThe @SpringBootApplication
annotation is added to the main class of a Spring Boot application to run it as a standalone JAR or WAR. It is a composite annotation that combines three key annotations:
@Configuration
@Bean
annotation.
@Bean
in this class return objects that are registered as Spring beans in the application context.@EnableAutoConfiguration
@ComponentScan
@Component
, @Configuration
, @Service
, @Repository
, etc.@EnableWebMvc
**:
DispatcherServlet
, HandlerMapping
, and ViewResolver
.spring-webmvc
dependency is detected on the classpath.@SpringBootApplication
AnnotationTo run a Spring Boot application, a main class annotated with @SpringBootApplication
is required. This class serves as the entry point for the application.
package com.app;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class Main {
public static void main(String[] args) {
SpringApplication.run(Main.class, args);
}
}