From d9cbba6b7b7c13a566d89f4f6fea7b0cd9c73654 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=96=AF=E7=8B=82=E7=9A=84=E7=8B=AE=E5=AD=90Li?= <15040126243@163.com> Date: Fri, 10 Apr 2026 15:01:18 +0800 Subject: [PATCH] =?UTF-8?q?update=20=E4=BC=98=E5=8C=96=20YmlPropertySource?= =?UTF-8?q?Factory=20=E4=BB=A3=E7=A0=81=E8=AD=A6=E5=91=8A=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/core/factory/YmlPropertySourceFactory.java | 6 ++++-- .../java/org/dromara/common/core/utils/StringUtils.java | 7 +++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/ruoyi-common/ruoyi-common-core/src/main/java/org/dromara/common/core/factory/YmlPropertySourceFactory.java b/ruoyi-common/ruoyi-common-core/src/main/java/org/dromara/common/core/factory/YmlPropertySourceFactory.java index af61b90ca..fcea14172 100644 --- a/ruoyi-common/ruoyi-common-core/src/main/java/org/dromara/common/core/factory/YmlPropertySourceFactory.java +++ b/ruoyi-common/ruoyi-common-core/src/main/java/org/dromara/common/core/factory/YmlPropertySourceFactory.java @@ -1,6 +1,7 @@ package org.dromara.common.core.factory; import org.dromara.common.core.utils.StringUtils; +import org.jspecify.annotations.Nullable; import org.springframework.beans.factory.config.YamlPropertiesFactoryBean; import org.springframework.core.env.PropertiesPropertySource; import org.springframework.core.env.PropertySource; @@ -8,6 +9,7 @@ import org.springframework.core.io.support.DefaultPropertySourceFactory; import org.springframework.core.io.support.EncodedResource; import java.io.IOException; +import java.util.Objects; /** * yml 配置源工厂 @@ -17,13 +19,13 @@ import java.io.IOException; public class YmlPropertySourceFactory extends DefaultPropertySourceFactory { @Override - public PropertySource createPropertySource(String name, EncodedResource resource) throws IOException { + public PropertySource createPropertySource(@Nullable String name, EncodedResource resource) throws IOException { String sourceName = resource.getResource().getFilename(); if (StringUtils.isNotBlank(sourceName) && StringUtils.endsWithAny(sourceName, ".yml", ".yaml")) { YamlPropertiesFactoryBean factory = new YamlPropertiesFactoryBean(); factory.setResources(resource.getResource()); factory.afterPropertiesSet(); - return new PropertiesPropertySource(sourceName, factory.getObject()); + return new PropertiesPropertySource(sourceName, Objects.requireNonNull(factory.getObject())); } return super.createPropertySource(name, resource); } diff --git a/ruoyi-common/ruoyi-common-core/src/main/java/org/dromara/common/core/utils/StringUtils.java b/ruoyi-common/ruoyi-common-core/src/main/java/org/dromara/common/core/utils/StringUtils.java index 21d19e644..b98c3c79a 100644 --- a/ruoyi-common/ruoyi-common-core/src/main/java/org/dromara/common/core/utils/StringUtils.java +++ b/ruoyi-common/ruoyi-common-core/src/main/java/org/dromara/common/core/utils/StringUtils.java @@ -555,4 +555,11 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils { return Strings.CS.replaceOnce(text, searchString, replacement); } + /** + * 测试 CharSequence 是否以所提供的任何后缀结尾。 + */ + public static boolean endsWithAny(final CharSequence sequence, final CharSequence... searchStrings) { + return Strings.CS.endsWithAny(sequence, searchStrings); + } + }