0

我想知道是否可以读取从属性文件中读取的所有密钥,而无需读取属性文件本身。我有这样配置的占位符

<context:property-placeholder
    system-properties-mode="OVERRIDE"
    ignore-resource-not-found="true"
    location="classpath:/defaults.properties, file:${config.location:/etc/default/example.properties}" />

这几乎可以解决我需要的所有案例。现在我想要一个配置概览页面,我可以在其中验证是否所有设置都已正确配置,而无需手动@Value将所有值注入其中@Controller并使用ModelAndView.

有什么想法可以解决这个问题,或者是否可以使用属性占位符?

4

1 回答 1

0

PropertyPlaceHolderConfigure不要公开他的属性,但您可以从 BeanDefinition 获取位置并以相同的结果加载它们。

BeanDefinition bd = configurableApplicationContext.getBeanFactory().getBeanDefinition("org.springframework.beans.factory.config.PropertyPlaceholderConfigurer#0");
    String[] locations = (String[]) bd.getPropertyValues().getPropertyValue("locations").getValue();
    Properties props = new Properties();
    for (String loc : locations) {
        props.putAll(PropertiesLoaderUtils.loadProperties(configurableApplicationContext.getResource(loc)));
    }
于 2012-12-14T11:55:44.843 回答