属性加载优化;开启 FastJSON 安全模式
This commit is contained in:
@@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
3
common/src/main/resources/META-INF/spring.factories
Normal file
3
common/src/main/resources/META-INF/spring.factories
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
# PropertySource Loaders
|
||||||
|
org.springframework.boot.env.PropertySourceLoader=\
|
||||||
|
com.jeesite.common.io.PropertyLoader
|
||||||
Reference in New Issue
Block a user