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); + } + }