Return to site

🍃🎓 SPRING CERTIFICATION QUESTION: PropertySourcesPlaceholderConfigurer

· vcp,spring,java

From which version does Spring set up a basic value-resolver for you?

  • 2.4
  • 3.4
  • 4.2
  • 4.3

#spring #certificationquestion

Definition of PropertySourcesPlaceholderConfigurer

PropertySourcesPlaceholderConfigurer is a class in the Spring Framework, a popular Java framework for building applications.

It is used to resolve and replace placeholder values in configuration files, such as property files or XML files, with actual values during the application's initialization process.

In Spring applications, you can define placeholders in your configuration files using the `${...}` syntax, like `${database.url}` or `${}`. PropertySourcesPlaceholderConfigurer scans the configuration files, finds these placeholders, and replaces them with real values provided from various sources, such as environment variables, system properties, or other configuration files.

This feature allows developers to externalize configuration details from the application's code, making it easier to modify settings without recompiling the entire application.

It promotes a more flexible and modular approach to managing configurations in Spring-based projects.

Java doc:

Answer explanation:

Spring from 4.3 sets up a basic value-resolver for you.

The PropertySourcesPlaceholderCofigurer will be already configured by a Spring Boot or a Spring,

If you're using a Spring after 4.3, this will be already in your application context.

But if you're using a Spring before 4.3, that means 4.2 or earlier, you will have to define it manually in your application context.

You have to be aware that if you are using any of these versions, you have to register this BeanFactoryPostProcessor explicitly in the application context.