From c20de5d3d2380360013df67fef6b3f3a1da330d4 Mon Sep 17 00:00:00 2001 From: thinkgem Date: Tue, 2 Jun 2020 13:46:29 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B1=9E=E6=80=A7=E5=8A=A0=E8=BD=BD=E4=BC=98?= =?UTF-8?q?=E5=8C=96=EF=BC=9B=E5=BC=80=E5=90=AF=20FastJSON=20=E5=AE=89?= =?UTF-8?q?=E5=85=A8=E6=A8=A1=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/jeesite/common/io/PropertyLoader.java | 13 +++++++++++-- common/src/main/resources/META-INF/spring.factories | 3 +++ 2 files changed, 14 insertions(+), 2 deletions(-) create mode 100644 common/src/main/resources/META-INF/spring.factories diff --git a/common/src/main/java/com/jeesite/common/io/PropertyLoader.java b/common/src/main/java/com/jeesite/common/io/PropertyLoader.java index b6ed453d..c757d0e8 100644 --- a/common/src/main/java/com/jeesite/common/io/PropertyLoader.java +++ b/common/src/main/java/com/jeesite/common/io/PropertyLoader.java @@ -9,31 +9,40 @@ import java.util.List; import java.util.Properties; import org.springframework.boot.env.OriginTrackedMapPropertySource; +import org.springframework.core.Ordered; import org.springframework.core.env.PropertySource; import org.springframework.core.io.Resource; +import com.alibaba.fastjson.parser.ParserConfig; + /** * 配置文件加载(Boot) * @author ThinkGem * @version 2018-10-16 */ -public class PropertyLoader implements org.springframework.boot.env.PropertySourceLoader{ +public class PropertyLoader implements org.springframework.boot.env.PropertySourceLoader, Ordered{ private static boolean isLoadPropertySource = false; @Override public String[] getFileExtensions() { - return new String[] { "properties", "yml" }; + return new String[] { "properties", "yml", "yaml" }; } @Override public List> load(String name, Resource resource) throws IOException { if (!isLoadPropertySource){ isLoadPropertySource = true; + ParserConfig.getGlobalInstance().setSafeMode(true); // 开启 FastJSON 安全模式 Properties properties = PropertiesUtils.getInstance().getProperties(); return Collections.singletonList(new OriginTrackedMapPropertySource("jeesite", properties)); } return Collections.emptyList(); } + + @Override + public int getOrder() { + return Integer.MIN_VALUE; + } } diff --git a/common/src/main/resources/META-INF/spring.factories b/common/src/main/resources/META-INF/spring.factories new file mode 100644 index 00000000..e3abe452 --- /dev/null +++ b/common/src/main/resources/META-INF/spring.factories @@ -0,0 +1,3 @@ +# PropertySource Loaders +org.springframework.boot.env.PropertySourceLoader=\ +com.jeesite.common.io.PropertyLoader