属性加载优化;开启 FastJSON 安全模式

This commit is contained in:
thinkgem
2020-06-02 13:46:29 +08:00
parent b62bbbd8e6
commit c20de5d3d2
2 changed files with 14 additions and 2 deletions

View File

@@ -9,31 +9,40 @@ import java.util.List;
import java.util.Properties; import java.util.Properties;
import org.springframework.boot.env.OriginTrackedMapPropertySource; import org.springframework.boot.env.OriginTrackedMapPropertySource;
import org.springframework.core.Ordered;
import org.springframework.core.env.PropertySource; import org.springframework.core.env.PropertySource;
import org.springframework.core.io.Resource; import org.springframework.core.io.Resource;
import com.alibaba.fastjson.parser.ParserConfig;
/** /**
* 配置文件加载Boot * 配置文件加载Boot
* @author ThinkGem * @author ThinkGem
* @version 2018-10-16 * @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; private static boolean isLoadPropertySource = false;
@Override @Override
public String[] getFileExtensions() { public String[] getFileExtensions() {
return new String[] { "properties", "yml" }; return new String[] { "properties", "yml", "yaml" };
} }
@Override @Override
public List<PropertySource<?>> load(String name, Resource resource) throws IOException { public List<PropertySource<?>> load(String name, Resource resource) throws IOException {
if (!isLoadPropertySource){ if (!isLoadPropertySource){
isLoadPropertySource = true; isLoadPropertySource = true;
ParserConfig.getGlobalInstance().setSafeMode(true); // 开启 FastJSON 安全模式
Properties properties = PropertiesUtils.getInstance().getProperties(); Properties properties = PropertiesUtils.getInstance().getProperties();
return Collections.singletonList(new OriginTrackedMapPropertySource("jeesite", properties)); return Collections.singletonList(new OriginTrackedMapPropertySource("jeesite", properties));
} }
return Collections.emptyList(); return Collections.emptyList();
} }
@Override
public int getOrder() {
return Integer.MIN_VALUE;
}
} }

View File

@@ -0,0 +1,3 @@
# PropertySource Loaders
org.springframework.boot.env.PropertySourceLoader=\
com.jeesite.common.io.PropertyLoader