From 8de027e0c779c33754572cd5f3153323f4f73ae3 Mon Sep 17 00:00:00 2001 From: Timi Date: Wed, 29 Oct 2025 11:20:59 +0800 Subject: [PATCH] add YamlPropertySourceFactory --- .../util/YamlPropertySourceFactory.java | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 src/main/java/com/imyeyu/spring/util/YamlPropertySourceFactory.java diff --git a/src/main/java/com/imyeyu/spring/util/YamlPropertySourceFactory.java b/src/main/java/com/imyeyu/spring/util/YamlPropertySourceFactory.java new file mode 100644 index 0000000..35f7305 --- /dev/null +++ b/src/main/java/com/imyeyu/spring/util/YamlPropertySourceFactory.java @@ -0,0 +1,24 @@ +package com.imyeyu.spring.util; + +import org.springframework.boot.env.YamlPropertySourceLoader; +import org.springframework.core.env.PropertySource; +import org.springframework.core.io.support.EncodedResource; +import org.springframework.core.io.support.PropertySourceFactory; + +import java.io.IOException; +import java.util.List; + +/** + * + * + * @author 夜雨 + * @since 2025-10-13 16:29 + */ +public class YamlPropertySourceFactory implements PropertySourceFactory { + + @Override + public @org.springframework.lang.NonNull PropertySource createPropertySource(String name, EncodedResource resource) throws IOException { + List> sources = new YamlPropertySourceLoader().load(resource.getResource().getFilename(), resource.getResource()); + return sources.get(0); + } +}