1

My code is in PropertyPlaceHolderConfigurer and it is depreceated .Any alternative. Code is below -

public void init(Properties properties) {

    // 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");
    }
Bhaskar Verma
  • 19
  • 1
  • 5

2 Answers2

1

If you read the javadocs that tells you what the replacement is.

Deprecated. as of 5.2; use org.springframework.context.support.PropertySourcesPlaceholderConfigurer instead which is more flexible through taking advantage of the Environment and PropertySource mechanisms.

In short use the PropertySourcesPlaceholderConfigurer.

Rule of thumb for the next deprecation you encounter, generally the replacement is mentioned in the java docs of the deprecated class.

M. Deinum
  • 115,695
  • 22
  • 220
  • 224
1

Just use:

final var configurer = new PropertySourcesPlaceholderConfigurer();
configurer.setProperties(properties);

Side note: It even works as a replacement for configuring properties over the XML configuration. See https://github.com/bojanantonovic/spring-properties-demo/blob/master/src/main/resources/my-config.xml.