首页 > 解决方案 > 访问使用 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

标签: springspring-bootspring-cloud

解决方案


推荐阅读