Skip to content

Commit

Permalink
Experiment #3 - configuration properties in variety of methods
Browse files Browse the repository at this point in the history
여러 방법으로 properties 사용 방법을 실험
행한 실험은:

* actuator endpoint 전부 개방
* `@ConstructorBinding` -> 2.2 기능
  * `@DefaultValue` -> 2.2 기능
  * `@DurationUnit`을 `@ConstructorBinding` 생성자에 사용
  * `@name`
* `.properties` 에 yaml 처럼 문서 구분하기
  * 프로파일 설정
  * 부트 프로퍼티 변화: `spring.profiles` -> `spring.config.activate.on-profile`
* `spring.config.import`
  * 여러개 `spring.config.import`
  * config tree
  * 확장자 없는 properties 파일
  • Loading branch information
djkeh committed Jul 12, 2021
1 parent c59068d commit ee1f206
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 2 deletions.
Expand Up @@ -2,7 +2,9 @@

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.ConfigurationPropertiesScan;

@ConfigurationPropertiesScan
@SpringBootApplication
public class FastcampusSpringBootPracticeApplication {

Expand Down
@@ -0,0 +1,29 @@
package com.fastcampus.springbootpractice.properties;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.ConstructorBinding;
import org.springframework.boot.context.properties.bind.DefaultValue;
import org.springframework.boot.context.properties.bind.Name;
import org.springframework.boot.convert.DurationUnit;

import java.time.Duration;
import java.time.temporal.ChronoUnit;

@ConstructorBinding
@ConfigurationProperties("iam")
public class CustomProperties {

/**
* 와아 이건 configuration processor 테스트
*/
private final Duration duration;

public CustomProperties(@DefaultValue("1") @DurationUnit(ChronoUnit.MILLIS) @Name("duration") Duration duration) {
this.duration = duration;
}

public Duration getDuration() {
return duration;
}

}
@@ -1,6 +1,7 @@
package com.fastcampus.springbootpractice.service;

import com.fastcampus.springbootpractice.logic.Sort;
import com.fastcampus.springbootpractice.properties.CustomProperties;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

Expand All @@ -12,9 +13,10 @@ public class SortService {
private final Sort<String> sort;


public SortService(@Qualifier("bubbleSort") Sort<String> sort) {
this.sort = sort;
public SortService(@Qualifier("bubbleSort") Sort<String> sort, CustomProperties customProperties) {
System.out.println("프로퍼티: " + customProperties.getDuration().toMillis() + " ms");
System.out.println("구현체: " + sort.getClass().getName());
this.sort = sort;
}

public List<String> doSort(List<String> list) {
Expand Down
8 changes: 8 additions & 0 deletions src/main/resources/application.properties
@@ -1 +1,9 @@
logging.logback.rollingpolicy.file-name-pattern=rolling.txt
management.endpoints.web.exposure.include=*
spring.config.import=classpath:my[.properties],configtree:/Users/Uno/Documents/github/fastcampus-spring-boot-practice/src/main/resources/tree/
spring.profiles.active=test

#---

spring.config.activate.on-profile=fastcampus | test
iam.duration=5s
1 change: 1 addition & 0 deletions src/main/resources/my
@@ -0,0 +1 @@
iam.duration=10s
1 change: 1 addition & 0 deletions src/main/resources/tree/iam/duration
@@ -0,0 +1 @@
12s

0 comments on commit ee1f206

Please sign in to comment.