1.实现EnvironmentPostProcessor
接口
public class MyEnvironmentPostProcessor implements EnvironmentPostProcessor {
private static final String PROPERTY_SOURCE_NAME = "defaultProperties";
@Override
public void postProcessEnvironment(ConfigurableEnvironment environment,
SpringApplication application) {
Map<String, Object> map = new HashMap<>();
map.put("localProperey", "value");
MapPropertySource target = (MapPropertySource) environment.getPropertySources().get(PROPERTY_SOURCE_NAME);
if (target == null) {
target = new MapPropertySource(PROPERTY_SOURCE_NAME, map);
}
environment.getPropertySources().addLast(target);
}
}
2.在META-INF的spring.factories中添加以下配置
org.springframework.boot.env.EnvironmentPostProcessor=\ com.xxxxx.MyEnvironmentPostProcessor
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。