67,549
社区成员




<springProperty scope="context" name="fluentHost" source="myapp.fluentd.host" defaultValue="localhost"/>
@Override
public void begin(InterpretationContext context, String elementName, Attributes attributes) throws ActionException {
String name = attributes.getValue(NAME_ATTRIBUTE);
String source = attributes.getValue(SOURCE_ATTRIBUTE);
Scope scope = ActionUtil.stringToScope(attributes.getValue(SCOPE_ATTRIBUTE));
String defaultValue = attributes.getValue(DEFAULT_VALUE_ATTRIBUTE);
if (OptionHelper.isEmpty(name) || OptionHelper.isEmpty(source)) {
addError("The \"name\" and \"source\" attributes of <springProperty> must be set");
}
ActionUtil.setProperty(context, name, getValue(source, defaultValue), scope);
}
private String getValue(String source, String defaultValue) {
if (this.environment == null) {
addWarn("No Spring Environment available to resolve " + source);
return defaultValue;
}
return this.environment.getProperty(source, defaultValue);
}
getValue 会从 environment 获得这个属性 (springboot 默认启动时加载的 标准servlet环境 )
scope 是对设置属性的域不同
local 是设置到 interpretaionContext 的属性map中
context 是设置到 interpretaionContext 中的上下文(是log的上下文)的属性map中
system 是设置到 System.setProperty(key, value);
static public void setProperty(InterpretationContext ic, String key, String value, Scope scope) {
switch (scope) {
case LOCAL:
ic.addSubstitutionProperty(key, value);
break;
case CONTEXT:
ic.getContext().putProperty(key, value);
break;
case SYSTEM:
OptionHelper.setSystemProperty(ic, key, value);
}
}
什么场景使用 , 我试了下
设置local 与 设置context 对我使用logback的属性没啥影响
先插个眼把 , 以后遇到再来