반응형

작성일자 : 2022.05.29

환경 : SpringBoot, Gradle

시나리오 : Gradle 에서 할당한 변수를 서버 사이드에서 Property 로 활용

 

 

1. Gradle 설정 추가

build.gradle

...

processResources {
	filesMatching('**/application.properties') {
		expand(project.properties)
	}
}

...

해당 설정 추가 이후 gradle build 에 processResources 작업이 추가된다.

 

 

2. 변수 선언

build.gradle

...

version = '0.0.1-SNAPSHOT'
ext {
	index = '1'
	string = "gradleString"
}

...

 

 

3. property 설정

application.properties

...

version=${version}
gradleIndex=${ext.index}
gradleString=${ext.string}

...

build.gradle 에서 선언한 processResources 작업에서 알맞은 Property 에 Gradle 변수를 할당

 

 

4. 확인

In controller

@Value("${version}")
private String version;
@Value("${gradleIndex}")
private Integer gradleIndex;
@Value("${gradleString}")
private String gradleString;

...

System.out.println(version);
System.out.println(gradleIndex);
System.out.println(gradleString);

...

 

 

반응형

'Java' 카테고리의 다른 글

[Spring] Profile 기준 Property 구분 적용  (0) 2023.06.28
[MyBatis] List 형식 멤버 변수 조회  (0) 2021.02.12
[Spring] Web Cache 적용  (0) 2020.12.19
[SpringBoot] H2 연동  (0) 2020.07.21
[Spring] App 구동 후 자동 작업 실행  (0) 2020.02.23

+ Recent posts