访问由EnvironmentPostProcessor注入的配置服务器属性

时间:2018-10-04 03:24:44

标签: spring spring-boot spring-cloud

我正在注入带有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://x.x.x.x:8888/config-service/defaultProperties-default.properties http://x.x.x.x:8888/defaultProperties-default.properties

0 个答案:

没有答案