'2019/09/16'에 해당되는 글 1건

  1. 2019.09.16 [SpringBoot] @PropertySource 로 yaml 파일 읽기

[SpringBoot] @PropertySource 로 yaml 파일 읽기

ITWeb/개발일반 2019.09.16 13:34

아래 문서에 보면 설명이 잘 나와 있습니다.

기록 하는 차원에서 남겨 봅니다.

 

https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-external-config.html#boot-features-external-config-yaml-shortcomings

 

24. Externalized Configuration

Getters and setters are usually mandatory, since binding is through standard Java Beans property descriptors, just like in Spring MVC. A setter may be omitted in the following cases:Maps, as long as they are initialized, need a getter but not necessarily a

docs.spring.io

1. If you use “Starters”, SnakeYAML is automatically provided by spring-boot-starter.
2. The YamlPropertySourceLoader class can be used to expose YAML as a PropertySource in the Spring Environment. Doing so lets you use the @Value annotation with placeholders syntax to access YAML properties.

 

SnakeYAML 이 기본 탑재

@Value 로 접근 가능

 

@PropertySource("classpath:/application.yml")
...
@Value("${spring.profiles.active}")
private String profile;

@PropertySource("classpath:/application.yml")
...
@Value("${spring.profiles.active}")
private String profile;

 

Trackbacks 0 : Comments 0

Write a comment