본문 바로가기

개발 이야기/Spring Boot

[스프링부트] Spring Boot의 Relaxed Binding 이란?

 

Spring Boot는 Environment프로퍼티를 @ConfigurationProperties 빈에 바인딩하기 위해 Relaxed Binding 규칙을 사용하기 때문에 Environment 프로퍼티 이름과 Bean 프로퍼티 이름을 정확히 일치할 필요가 없다. Relaxed Binding이란 프로퍼티와 환경 변수들의 구분을 어느정도 유연한 규칙으로 동일하게 인식한다고 이해하면 된다. 대표적으로 Camel case와 Snake case로 각각 설정된 값들이 있다면 이를 동일한 설정으로 이해하며, 우선순위에 맞게 내부적으로는 1개의 값으로 설정한다.

 

대시(-)로 구분된 환경 프로퍼티(ex. context-pathcontextPath에 바인드)와 대문자로 작성(capitalized)된 환경 프로퍼티(ex. PORTport에 바인드)를 생각해보면 이해가 된다. 사실 각 프로퍼티 소스에 대해서 권장되는 방법이 있고, 대부분의 경우에는 소문자를 활용하는 Kebab case가 권장되는데 아래 정리해본다.

1. Properties Files(프로퍼티 파일)

.properties 파일에서는 소문자 Kebab case가 권장된다. 예를들면 spring.main.log-startup-info=something과 같다.

2. YAML Files(YAML 파일)

.yml 파일에서도 소문자 Kebab case가 권장된다. 예를들면 spring.main.log-startup-info=something과 같다.

3. Environment Variables(환경 변수)

환경 변수는 대문자 Snake case로 사용하고, 기존 포맷이 이와 다른 경우 아래 규칙으로 변경하여 사용하는 것이 권장된다. 예를들면spring.main.log-startup-info=somethingSPRING_MAIN_LOGSTARTUPINFO=something으로 변환한다.

 

1) Replace dots (.) with underscores (_).
2) Remove any dashes (-).
3) Convert to uppercase.

4. System properties(시스템 프로퍼티)

Kebab case, Camel case, Snake case 모두 사용 가능하다.

 


 

아래는 Spring Boot의 공식 문서인데 자세한 내용은 공식 문서를 참고하자.

 

 

Spring Boot Features

Graceful shutdown is supported with all four embedded web servers (Jetty, Reactor Netty, Tomcat, and Undertow) and with both reactive and Servlet-based web applications. It occurs as part of closing the application context and is performed in the earliest

docs.spring.io