@Value not resolved when using @PropertySource annotation.

Spring’s gotcha-of-the-day is around using @Value to resolve property placeholders in combination with @PropertySource.

I had the following Spring Java configuration:

public class TestAppConfig {

    private String queue;
    public String getQueue() {  
        return queue;  

But the value in “queue” was not resolving - it returned “${queue.name}” as the value.

It turns out that I needed the following magical incantation to get it to work.

public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() {  
    return new PropertySourcesPlaceholderConfigurer();  
Java  Spring