본문으로 건너뛰기

@SpringBootApplication

@SpringBootApplication 어노테이션에 대해서 간단히 알아보자

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

@SpringBootApplication
public class ExampleApplication {

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

}

내부를 살펴보면

  • @SpringBootConfiguration
  • @EnableAutoConfiguration
  • @ComponentScan 을 포함하고 있다.

스프링 부트의 main 메서드는 @SpringBootApplication 어노테이션을 가지고 있는데 이것은
ComponentScan + configuraion + EnableAutoConfiguration를 합친 어노테이션 이라볼 수 있다.

@Target(value = {ElementType.TYPE})
@Retention(value = RetentionPolicy.RUNTIME)
@Documented
@Inherited
@SpringBootConfiguration
@EnableAutoConfiguration
@ComponentScan(excludeFilters = {
@ComponentScan.Filter(type = FilterType.CUSTOM, classes = {TypeExcludeFilter.class}),
@ComponentScan.Filter(type = FilterType.CUSTOM, classes = {AutoConfigurationExcludeFilter.class})})
public @interface SpringBootApplication {

@AliasFor(annotation = EnableAutoConfiguration.class)
public Class<?>[] exclude() default {};

@AliasFor(annotation = EnableAutoConfiguration.class)
public String[] excludeName() default {};

@AliasFor(annotation = ComponentScan.class, attribute = "basePackages")
public String[] scanBasePackages() default {};

@AliasFor(annotation = ComponentScan.class, attribute = "basePackageClasses")
public Class<?>[] scanBasePackageClasses() default {};

@AliasFor(annotation = ComponentScan.class, attribute = "nameGenerator")
public Class<? extends BeanNameGenerator> nameGenerator() default BeanNameGenerator.class;

@AliasFor(annotation = Configuration.class)
public boolean proxyBeanMethods() default true;
}