본문으로 바로가기

yml 파일은 문자와 문자 사이에 하이픈(-)을 넣는 것을 선호한다. 

1. 사용하는 메인 컨트롤러에 어노테이션 추가

@ConfigurationPropertiesScan

2. 프로퍼티 파일 생성

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.ConstructorBinding;

import lombok.Data;


@Data
@ConstructorBinding
@ConfigurationProperties(prefix = "spring")
public class PropertiesConfig {
	
	//depth-1
	private String profiles;
	private Depth2 depth2;
	private Depth3 depth3;
	
	//depth-2
	@Data
	public static class Depth2 {
		
		private String depth2Value;
	}

	//depth-3
	@Data
	public static class Depth3 {
		
		private Depth3Sub depth3Sub;
		
		@Data
		public static class Depth3Sub {
			private String depth3SubValue1;
			private String Depth3SubValue2;
		}
	}
}

3. 사용

@ConfigurationPropertiesScan
public class MainController {
	@GetMapping(value = "/")
	public Mono<String> main() throws Exception {
    	String html = "";
        html += "<h1>서버("+ propertiesConfig.getProfiles() +")</h1>";
        return Mono.just(html);
    }
}

 

'JAVA > SOURCECODE' 카테고리의 다른 글

Response Map Sorted(Map To Json)  (0) 2022.03.30
jasypt 알고리즘 AES256 변경법  (0) 2022.03.12
Generate Request  (0) 2021.11.04
JSON String to VO object  (0) 2021.08.31
jar 실행시 build 위치 추가  (0) 2021.03.02