참고 문서
외부링크
spring-boot document : http://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/
spring-boot feature : http://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#boot-features-spring-application
spring boot 동작 원리 : https://dzone.com/articles/spring-boot-my-favorite
spring-boot
spring boot life-cycle
Cosysto Gimbh 라는 사람이 life-cycle에 대한 flow 를 아주 잘 그려놓았다.
실제 구현체 이름은 매우 길고 복잡하다. (e.g. ConfigurationWarningsApplicationContextInitializer)
spring application 내부에서 실제로 어떤 일이 일어나는지에 집중하도록 긴 이름은 짧게 축약하였다.
ApplicationContext 생성(=SpringApplication.run())
- Listener 생성 및 시작
- Environment 준비
- Context 생성
- Context 준비
- Environment 세팅
- 후처리(post process)
- Initializer 초기화(apply initializer)
- Context 로드
- Source 로드
- BeanDefinitionLoader 에 Source , Context 탑재
- BeanDefinitionLoader 로드
- 종료
- Context Refresh
ApplicationContext 는 SpringApplication의 몸통에 해당하는 실제 instance의 추상화이다.
SpringApplication
SpringApplication 의 Entry point 는 반드시 특정 package를 지정하고, 그 하위에 위치시켜야 한다. (=Default package path에 entry point 시작 금지)
그렇지 않으면 ** WARNING ** : Your ApplicationContext is unlikely to start due to a @ComponentScan of the default package. 이 발생한다.
@SpringBootApplication 을 사용하면 다음 Annotation 을 생략 가능하다.
Source Code
@Target(ElementType.TYPE) @Retention(RetentionPolicy.RUNTIME) @Documented @Inherited @Configuration @EnableAutoConfiguration @ComponentScan public @interface SpringBootApplication { /** * Exclude specific auto-configuration classes such that they will never be applied. * @return the classes to exclude */ Class<?>[] exclude() default {}; }
SpringApplicationRunListener
ConfigurableEnvironment
ConfigurableApplicationContext
실제로 호출되는 implementation 은 AnnotationConfigEmbddedWebApplicationContext 이다.