mirror of
https://gitee.com/dromara/RuoYi-Vue-Plus.git
synced 2026-04-15 06:53:15 +08:00
update 优化 YmlPropertySourceFactory 代码警告问题
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user