spring - 访问使用 EnvironmentPostProcessor 注入的配置服务器属性
问题描述
我正在注入带有 / 的属性EnvironmentPostProcessor
,它们是来自另一个属性 xml 文件的旧属性,我如何访问带有 REST URL 的属性列表?
@Component
public class SpringCloudConfigRuntimeEnvironmentPostProcessor implements
EnvironmentPostProcessor {
@Override
public void postProcessEnvironment(ConfigurableEnvironment environment, SpringApplication application) {
LinkedHashMap<String, Object> map = new LinkedHashMap<>();
map.put("com.xyz.jdbcUrl", "x.y.z");
MapPropertySource propertySource = new MapPropertySource("defaultProperties", map);
environment.getPropertySources().addLast(propertySource);
我将它添加到 spring.factories
org.springframework.boot.env.EnvironmentPostProcessor=com.xyz.configservice.config.SpringCloudConfigRuntimeEnvironmentPostProcessor
当我打印环境时,我确实看到它们正在加载
在 application.yml
server:
port: 8888
spring:
application:
name: config-service
我找不到正确的语法来获取我加载的那些属性,其中有几个我尝试过: http://xxxx:8888/config-service/defaultProperties-default.properties http://xxxx:8888/defaultProperties-默认.properties
解决方案
推荐阅读
- docker - Docker swarm 模式路由网格无法按预期工作
- asp.net-core-2.0 - 从 2.2.1 更新后不保存 EF Core 2.2.3 子记录
- javascript - 当我单击一个标记时,我需要放大两个级别才能看到位置
- android - 全局变量在内部类中不为空,但在外部为空
- c - STM32只第一次正常工作,然后掉字节
- qt - 为什么子 QGraphicsObject 不能正确重绘其背景
- nginx - Kubernetes nginx 入口 - 阻止主机标头错误的请求
- android - 如何将数据作为意图从子活动传递到父活动
- django - 在部署环境中多次使用 Django 或 wsgi app init?
- reactjs - 如何使用本地 tinymce js 在 React 中加载 tinymce 编辑器