Contents
- Environment
- MessageSource
- ResourceLoader
Environment
applicationContext 는 bean factory의 기능 외에도 여러가지 기능이 있다.
Environment 는 그 기능들 중 하나
EnvironmentCapable 은 2가지 기능으로 profile 과 propertie가 있는데
그 중 한가지인 Profile 기능에 대해서 봐보겠다.
Profile
Profile 은 bean 들의 묶음인데
특정 환경에서는 이런 bean 들을 쓰겠다 하고 선언을 할 수 가 있다.
빈에 profile을 설정해두면 해당 빈은 test profile 로 들어왔을 경우에만 사용가능 하다.
Propertie
이런식으로 가져와서 쓸 수 있다.
스프링 부트에서는 Profile 에 따라서 properties 가 적용이 되도록 할 수 있는데,
application-test.properties 의 컨벤션으로 properties를 만들경우
test profile 에서 해당 properties 를 사용 하도록 되어있다.
(참고)
Spring Boot Features
If you need to call remote REST services from your application, you can use the Spring Framework’s RestTemplate class. Since RestTemplate instances often need to be customized before being used, Spring Boot does not provide any single auto-configured RestT
docs.spring.io
MessageSource
메세지를 다국화 하는 기법
MessageSource.getMessage() 에 Locale.KOREA 를 파라미터로 주게 되면
messages_ko_KR.properties 를 읽게 된다.
스프링 부트에서는 messages. 뒤로 시작하는건 이미 메세지소스로 읽을 수 있도록 설정이 되어있다.
ResourceLoader
리소스를 읽어주는 인터페이스
resources 폴더 밑에 있는 것들은
빌드를 하면서 target 폴더 밑에 classpath 밑으로 들어간다.
ResourceLoader 를 통해 classpath 밑에 텍스트 파일을 읽을 수 있다.
'Spring > Core' 카테고리의 다른 글
Spring Core - Validation, Data binding 추상화 (0) | 2020.04.18 |
---|---|
Spring Core - Resource 추상화 (0) | 2020.04.18 |
Spring Core - bean 의 스코프 (0) | 2020.04.16 |
Spring Core - Annotation (0) | 2020.04.16 |
Spring Core - IOC 컨테이너와 빈 (0) | 2020.04.16 |