首页 > 解决方案 > PropertyPlaceHolderConfigurer 替代方案

问题描述

我的代码在 PropertyPlaceHolderConfigurer 中,它已被弃用。任何替代方案。代码如下 -

公共无效初始化(属性属性){

    // SPECIFIC properties (database connection, handlers)
    if (properties != null) {
          ConfigurableApplicationContext context = new ClassPathXmlApplicationContext(new String[] { 
                 CONTEXT }, false);
             PropertyPlaceholderConfigurer configurer = new PropertyPlaceholderConfigurer();--Problem 
                                                                                                here
           configurer.setProperties(properties);
      
           context.addBeanFactoryPostProcessor(configurer);
            context.refresh();
           this.DefinitionDao = (DefinitionDao) 
           context.getBean("DefinitionDao");
            this.logger = (Logger) context.getBean("Logger");
    }

标签: javaspring

解决方案


如果您阅读了告诉您替换是什么的javadocs 。

已弃用。从 5.2 开始;org.springframework.context.support.PropertySourcesPlaceholderConfigurer通过利用EnvironmentPropertySource机制,使用更灵活的方法。

总之使用PropertySourcesPlaceholderConfigurer.

您遇到的下一次弃用的经验法则,通常在弃用类的 java 文档中提到替换。


推荐阅读