From c60f23ad2ee624081f0970cd098275553c44f9e7 Mon Sep 17 00:00:00 2001 From: Uno Date: Mon, 12 Jul 2021 02:04:45 +0900 Subject: [PATCH 1/6] Add #3 - properties migrator MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 넣어보고, 프로퍼티에 과거 로그백 설정 세팅 테스트 돌리니 안내 문구 표시되는 것 확인 ``` Property source 'Config resource 'classpath:/application.properties' via location 'optional:classpath:/'': Key: logging.pattern.rolling-file-name Line: 1 Replacement: logging.logback.rollingpolicy.file-name-pattern ``` --- build.gradle | 3 ++- src/main/resources/application.properties | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/build.gradle b/build.gradle index e07df82..cfd24cc 100644 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,5 @@ plugins { - id 'org.springframework.boot' version '2.5.2' + id 'org.springframework.boot' version '2.4.0' id 'io.spring.dependency-management' version '1.0.11.RELEASE' id 'java' } @@ -13,6 +13,7 @@ repositories { } dependencies { + implementation 'org.springframework.boot:spring-boot-properties-migrator' implementation 'org.springframework.boot:spring-boot-starter-web' testImplementation 'org.springframework.boot:spring-boot-starter-test' } diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 8b13789..786f4b2 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -1 +1 @@ - +logging.pattern.rolling-file-name=rolling.txt From 919667c774728fd1350ea324dcc49d747d251714 Mon Sep 17 00:00:00 2001 From: Uno Date: Mon, 12 Jul 2021 02:05:59 +0900 Subject: [PATCH 2/6] Update #3 - logback properties following the guide MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 가이드에 맞게 수정하고 안내 문구 사라짐 확인 --- src/main/resources/application.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 786f4b2..728ad00 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -1 +1 @@ -logging.pattern.rolling-file-name=rolling.txt +logging.logback.rollingpolicy.file-name-pattern=rolling.txt From c59068d8b19617e7583b8cc825438504321001ab Mon Sep 17 00:00:00 2001 From: Uno Date: Tue, 13 Jul 2021 05:14:53 +0900 Subject: [PATCH 3/6] Add #3 - actuator, configuration processor MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 액츄에이터, configuration processor 의존성 추가 * configuration processor: `annotationProcessor`를 사용해야 함 * ConfigurationProperties 클래스의 메타 정보를 .properties 파일과 이어주는 기능 --- build.gradle | 2 ++ 1 file changed, 2 insertions(+) diff --git a/build.gradle b/build.gradle index cfd24cc..6b2693b 100644 --- a/build.gradle +++ b/build.gradle @@ -13,9 +13,11 @@ repositories { } dependencies { + implementation 'org.springframework.boot:spring-boot-starter-actuator' implementation 'org.springframework.boot:spring-boot-properties-migrator' implementation 'org.springframework.boot:spring-boot-starter-web' testImplementation 'org.springframework.boot:spring-boot-starter-test' + annotationProcessor 'org.springframework.boot:spring-boot-configuration-processor' } test { From ee1f20641a1de8233334760bd7ff2817bd82ae59 Mon Sep 17 00:00:00 2001 From: Uno Date: Tue, 13 Jul 2021 05:20:59 +0900 Subject: [PATCH 4/6] Experiment #3 - configuration properties in variety of methods MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 여러 방법으로 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 파일 --- ...stcampusSpringBootPracticeApplication.java | 2 ++ .../properties/CustomProperties.java | 29 +++++++++++++++++++ .../service/SortService.java | 6 ++-- src/main/resources/application.properties | 8 +++++ src/main/resources/my | 1 + src/main/resources/tree/iam/duration | 1 + 6 files changed, 45 insertions(+), 2 deletions(-) create mode 100644 src/main/java/com/fastcampus/springbootpractice/properties/CustomProperties.java create mode 100644 src/main/resources/my create mode 100644 src/main/resources/tree/iam/duration diff --git a/src/main/java/com/fastcampus/springbootpractice/FastcampusSpringBootPracticeApplication.java b/src/main/java/com/fastcampus/springbootpractice/FastcampusSpringBootPracticeApplication.java index 581db64..0e33857 100644 --- a/src/main/java/com/fastcampus/springbootpractice/FastcampusSpringBootPracticeApplication.java +++ b/src/main/java/com/fastcampus/springbootpractice/FastcampusSpringBootPracticeApplication.java @@ -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 { diff --git a/src/main/java/com/fastcampus/springbootpractice/properties/CustomProperties.java b/src/main/java/com/fastcampus/springbootpractice/properties/CustomProperties.java new file mode 100644 index 0000000..018ac12 --- /dev/null +++ b/src/main/java/com/fastcampus/springbootpractice/properties/CustomProperties.java @@ -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; + } + +} \ No newline at end of file diff --git a/src/main/java/com/fastcampus/springbootpractice/service/SortService.java b/src/main/java/com/fastcampus/springbootpractice/service/SortService.java index 1b1bc8a..cca967e 100644 --- a/src/main/java/com/fastcampus/springbootpractice/service/SortService.java +++ b/src/main/java/com/fastcampus/springbootpractice/service/SortService.java @@ -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; @@ -12,9 +13,10 @@ public class SortService { private final Sort sort; - public SortService(@Qualifier("bubbleSort") Sort sort) { - this.sort = sort; + public SortService(@Qualifier("bubbleSort") Sort sort, CustomProperties customProperties) { + System.out.println("프로퍼티: " + customProperties.getDuration().toMillis() + " ms"); System.out.println("구현체: " + sort.getClass().getName()); + this.sort = sort; } public List doSort(List list) { diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 728ad00..bccd620 100644 --- a/src/main/resources/application.properties +++ b/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 diff --git a/src/main/resources/my b/src/main/resources/my new file mode 100644 index 0000000..71b209c --- /dev/null +++ b/src/main/resources/my @@ -0,0 +1 @@ +iam.duration=10s \ No newline at end of file diff --git a/src/main/resources/tree/iam/duration b/src/main/resources/tree/iam/duration new file mode 100644 index 0000000..36c172f --- /dev/null +++ b/src/main/resources/tree/iam/duration @@ -0,0 +1 @@ +12s \ No newline at end of file From d1c1b7ff19c87bfbacfd460e6b228c2c53ec3ab6 Mon Sep 17 00:00:00 2001 From: Uno Date: Tue, 13 Jul 2021 05:23:02 +0900 Subject: [PATCH 5/6] =?UTF-8?q?Fix=20#3=20-=20config=20tree=20=EB=B2=84?= =?UTF-8?q?=EA=B7=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit config tree 하면 `Duration` 타입 convert 안 되는 버그 발견. 알고 보니 2.4.1 에서 패치됐다. * spring-projects/spring-boot#24171 --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 6b2693b..43ed04f 100644 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,5 @@ plugins { - id 'org.springframework.boot' version '2.4.0' + id 'org.springframework.boot' version '2.4.1' id 'io.spring.dependency-management' version '1.0.11.RELEASE' id 'java' } From 6c42955937875b84c67865fbf9cdc01c4f7c6edd Mon Sep 17 00:00:00 2001 From: Uno Date: Tue, 13 Jul 2021 05:26:49 +0900 Subject: [PATCH 6/6] =?UTF-8?q?Experiment=20#3=20-=20=ED=94=84=EB=A1=9C?= =?UTF-8?q?=ED=8C=8C=EC=9D=BC=EB=9F=AC=20=ED=85=8C=EC=8A=A4=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Flight Recorder, BufferingApplicationStartup 테스트 * flight recorder * 코드 짠다 * 프롬프트에서 `java -XX:StartFlightRecording:filename=recording.jfr,duration=10s -jar ${jar파일}` 로 부트 실행 * 이 내용은 `FlightRecorderApplicationStartup` 안에 javadoc으로 가이드 되어 있음 * 부트 실행 종료 * 프로젝트 루트에서 `recording.jfr` 확인 * JDK Mission Control 실행 * 파일 로드 * BufferingApplicationStartup * 코드 구현 * 평범하게 부트 실행 * actuator로 `/startup` 항목 추가된 것 확인 * POST 로 데이터 조회: `curl -X POST http://localhost:8080/actuator/startup | jq` --- .../FastcampusSpringBootPracticeApplication.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/fastcampus/springbootpractice/FastcampusSpringBootPracticeApplication.java b/src/main/java/com/fastcampus/springbootpractice/FastcampusSpringBootPracticeApplication.java index 0e33857..7523505 100644 --- a/src/main/java/com/fastcampus/springbootpractice/FastcampusSpringBootPracticeApplication.java +++ b/src/main/java/com/fastcampus/springbootpractice/FastcampusSpringBootPracticeApplication.java @@ -2,14 +2,19 @@ import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.context.metrics.buffering.BufferingApplicationStartup; import org.springframework.boot.context.properties.ConfigurationPropertiesScan; +import org.springframework.core.metrics.jfr.FlightRecorderApplicationStartup; @ConfigurationPropertiesScan @SpringBootApplication public class FastcampusSpringBootPracticeApplication { public static void main(String[] args) { - SpringApplication.run(FastcampusSpringBootPracticeApplication.class, args); + SpringApplication application = new SpringApplication(FastcampusSpringBootPracticeApplication.class); +// application.setApplicationStartup(new FlightRecorderApplicationStartup()); + application.setApplicationStartup(new BufferingApplicationStartup(1000)); + application.run(args); } }