This forum is now a read-only archive. All commenting, posting, registration services have been turned off. Those needing community support and/or wanting to ask questions should refer to the Tag/Forum map, and to http://spring.io/questions for a curated list of stackoverflow tags that Pivotal engineers, and the community, monitor.

AnnouncementAnnouncement Module

Collapse

No announcement yet.

Variable replacement for @Value using @PropertySource and PSPHCPage Title Module

Variable replacement for @Value using @PropertySource and PSPHC

Mar 8th, 2012, 08:57 PM

I have been trying to use variable replacements inside @Value annotations using the new @PropertySource mechanism. What I've found is that for each class I annotated with @PropertySource and @Configuration required a static Bean definition for the PropertySourcesPlaceholderConfigurer. The way I read the spring documentation was that the PropertySourcesPlaceholderConfigurer was only needed to be defined once somewhere in the app - NOT in each class with @PropertySource annotations. The example below shows the situation. The code below will replace the ${title} with the value from the respective properties file value in both config classes. If I was to remove the static method in one of the classes that class then no longer will do variable replacements in the @Value annotation.

Is this the correct "spring" way of using @PropertySource with PropertySourcePlaceholderConfigurer?