파란하늘의 지식창고
@ConfigurationProperties를 사용하지 않고 method 내에서 properties의 변수 binding 하기
Study/Java 2024. 2. 4. 14:05

Spring Boot에서 @ConfigurationProperties를 사용하지 않고 method 내에서 Binder class를 사용해서 environment의 지정된 값들을 지정된 객체에 binding 할 수 있다. Binder class는 Spring Boot 2.0 이후 제공되는 기능이다 property-binding-in-spring-boot-2-0. 다음과 같이 Binder를 사용하여 설정 값을 binding 할 수 있다: @Test void testEnv() { ConfigurableEnvironment environment = new StandardEnvironment(); Map map = new HashMap(); map.put("myapp.database.url", "jdbc:mysq..

Spring Boot 2.0에서 Deprecated 된 RelaxedPropertyResolver 변경하기
Study/Java 2018. 10. 23. 16:18

Spring Boot 1.x 에서 잘 사용하고 있던 RelaxedPropertyResolver가 2.0 이후 Deprecated 되었다. Binder를 사용하는 것을 Migration Guide에서 권장하고 있다. Spring Boot 2.0 Migration Guide #Relaxed Binding 참고 Relaxed Bind 2.0 위키 문서 Spring Boot 1.x에서 RelaxedPropertyResolver를 사용하던 방식은 다음과 같다. @Bean public Map uiPropertiesMap(Environment environment) { return new RelaxedPropertyResolver(environment, "ui.").getSubProperties(""); } 단순히 ..