JunsuLime / spring-cloud-native-explorer

Spring cloud explorer
1 stars 0 forks source link

스프링 부트의 AutoConfiguration #24

Open JunsuLime opened 2 years ago

JunsuLime commented 2 years ago

학습 전 목표

META-INF/spring.factories 프로젝트의 여 파일을 확인해서 의존하는 auto-configuration 을 파악할 수 있다. auto-configuration 은 위의 방법으로만 등록되어야하며, component-scan 등이 적용되면 안된다.

import 가 필요하다면 명시적으로 @Import 를 사용하자.

AutoConfiguration 의 순서를 주고 싶다면

condition 을 통해 조건에 맞게 bean 등록 가능

그럼 위와 같이 어찌저찌해서 AutoConfiguration 을 잘 만들었다믄 어케 테스트하느냐 ApplicationContextRunner 를 통해 CustomAutoConfiguration 을 invoke 시키자

그래!! 여기까지 auto-configuration. 만들고 검증까지했어 그럼 이를 확장해서 custom starter 를 만들어보자.

일반적으로 starter 는 auto-configure 과 acme(에크미) 라 불리는 커스터마이즈 된 infrastructor 를 가지고있다. (확장가능한 구조로 구성되어있)

그래서 starter 는 user 가 쉽게 시작할수있게 해준다 (default 값이 있고, 이를 확장가능하게 사용자에게 열어줌)

custom starter 는

  1. autoconfigure 모듈을 가지고 있다. (acme 를 위한 auto-configuration 코드를 가지고 있는)
  2. starter 모듈을 가지고있다. (이는 autoconfigure 에 의존성을 제공하는 모듈이다.)

(이 두 모듈은 꼭 분리할 필요는 없다.)

If the auto-configuration is relatively straightforward and does not have optional feature, merging the two modules in the starter is definitely an option.

만들면 acme-spring-boot-starter. 욜케 이름 지어라

그럼 위의 모듈 하나씩 보자

AutoConfigure

Starter

https://docs.spring.io/spring-boot/docs/current/reference/html/features.html#features.kotlin.api

JunsuLime commented 2 years ago

AutoConfiguration 발표 인덱스

  1. Spring vs Spring boot
  2. AutoConfiguration 란 무엇인가? (개념 및 구조)
  3. 코드를 까면서 알아보자 (RedisAutoConfiguration)
  4. CustomAutoConfiguration 은 어떻게 만들면 되는가?