From 6dffcc8573731c36f5e245eba435783a7fb69ffa Mon Sep 17 00:00:00 2001 From: jackzlz Date: Fri, 8 Mar 2024 11:56:30 +0800 Subject: [PATCH] =?UTF-8?q?yml=E8=A7=A3=E6=9E=90=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E5=8D=A0=E4=BD=8D=E7=AC=A6=20(#5045)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../otter/canal/client/adapter/support/YamlUtils.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/client-adapter/common/src/main/java/com/alibaba/otter/canal/client/adapter/support/YamlUtils.java b/client-adapter/common/src/main/java/com/alibaba/otter/canal/client/adapter/support/YamlUtils.java index 0c954104..c3d6c9b0 100644 --- a/client-adapter/common/src/main/java/com/alibaba/otter/canal/client/adapter/support/YamlUtils.java +++ b/client-adapter/common/src/main/java/com/alibaba/otter/canal/client/adapter/support/YamlUtils.java @@ -4,6 +4,7 @@ import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; import java.nio.charset.StandardCharsets; +import java.util.Arrays; import java.util.List; import java.util.Map; import java.util.Properties; @@ -18,6 +19,7 @@ import org.springframework.core.env.PropertySource; import org.springframework.core.io.ByteArrayResource; import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.Resource; +import org.springframework.util.PropertyPlaceholderHelper; public class YamlUtils { @@ -87,7 +89,13 @@ public class YamlUtils { } ConfigurationPropertySource sources = new MapConfigurationPropertySource(properties); - Binder binder = new Binder(sources); + PropertyPlaceholderHelper propertyPlaceholderHelper = new PropertyPlaceholderHelper("${", "}"); + Binder binder = new Binder(Arrays.asList(sources), value -> { + if (value instanceof String) { + return propertyPlaceholderHelper.replacePlaceholders((String)value, baseProperties); + } + return value; + }); return binder.bind(prefix, Bindable.of(clazz)).get(); } catch (Exception e) { throw new RuntimeException(e);