【问题标题】:Use Commons Configuration 2 as PropertySource in Spring在 Spring 中使用 Commons Configuration 2 作为 PropertySource
【发布时间】:2016-04-01 09:37:03
【问题描述】:

Commons Configuration 2.0 已发布。使用 Commons Configuration 1.0 有一个 Spring 模块工厂 bean (org.springmodules.commons.configuration.CommonsConfigurationFactoryBean) 允许直接使用 Spring 的 Commons Configuration 属性占位符配置器。由于不再维护, 问题是如何使用 Commons Configuration 2.0 做到这一点。

当然应该可以复制现有的 Spring 模块 源代码到项目并将其迁移到 2.0。我知道 Spring 提供了 YAML,但它应该仍然是 Commons Configuration(现有的 XML 配置文件不应该受到影响)。

【问题讨论】:

    标签: spring apache-commons-config


    【解决方案1】:

    我为 Commons Configuration 贡献了一个 PropertySource,它是 >=2.1 版本的一部分:org.apache.commons.configuration2.spring.ConfigurationPropertySource

    例如在扩展的 PropertySourcesPlaceholderConfigurer 中使用它:

    public class ApacheCommonsConfigPlaceholderConfigurer extends PropertySourcesPlaceholderConfigurer {
    
       public ApacheCommonsConfigPlaceholderConfigurer(Configuration configuration) {
         ConfigurationPropertySource apacheCommonsConfigPropertySource =
            new ConfigurationPropertySource(configuration.getClass().getName(), configuration);
         MutablePropertySources propertySources = new MutablePropertySources();
         propertySources.addLast(apacheCommonsConfigPropertySource);
         setPropertySources(propertySources);
       }
    }
    

    如果这个问题得到解决,代码会更简单:https://jira.spring.io/browse/SPR-9631

    另见:http://mail-archives.apache.org/mod_mbox/commons-user/201604.mbox/%3C44F558D5-0A26-4711-9658-39BD9052D751@capitalone.com%3E

    【讨论】:

      猜你喜欢
      • 2020-10-17
      • 2011-07-12
      • 2017-11-11
      • 2017-01-17
      • 1970-01-01
      • 1970-01-01
      • 2019-10-07
      • 2013-03-25
      • 2015-05-17
      相关资源
      最近更新 更多