7

I am starting to learn Spring annotations. I'm currently using the @PropertySource annotation in my Configuration Class to resolve properties values and everything works fine, but then I read about PropertySourcesPlaceholderConfigurer.

When or why I should use that?

Andrew Regan
  • 5,087
  • 6
  • 37
  • 73
Djordje Vuckovic
  • 383
  • 1
  • 5
  • 11

1 Answers1

4

From @PropertySource javadoc

...
Note, however, that explicit registration of a PropertySourcesPlaceholderConfigurer via a static @Bean method is typically only required if you need to customize configuration such as the placeholder syntax, etc. See the "Working with externalized values" section of Configuration @Configuration's javadocs and "a note on BeanFactoryPostProcessor-returning @Bean methods of Bean @Bean's javadocs for details and examples. Specifically, if no bean post-processor (such as a PropertySourcesPlaceholderConfigurer) has registered an embedded value resolver for the ApplicationContext, Spring will register a default embedded value resolver which resolves placeholders against property sources registered in the Environment.
...

Well, if simple words if you need set up or get more control over property configuration bean such as PropertySourcesPlaceholderConfigurer you could define it. Otherwise it can be ommited.But if you use version of Spring prior 4.3.0, this bean has to be declared for resolve @Value.

For get more details:

I hope it'll a little help you)

Manuel Jordan
  • 15,253
  • 21
  • 95
  • 158
Anthony
  • 571
  • 3
  • 11