Title: PropertySourcesPlaceholderConfigurer With Specific Value Parser
Tags: java;spring;configuration;properties-file
Question: I understand that the ```${...}```-notation works as long as it contains references to other properties. However, I want to extend that parsing algorithm.

Here's the properties-file:

```connection.http.connectTimeout=15000
#connection.http.readTimeout=${connection.http.connectTimeout}
connection.http.readTimeout=%{30*1000}
```

The second line would still work and set ```readTimeout``` to 15000, but I want to make line 3 work. I have to say that I don't care what prefix and postfix I use, the above example uses ```%{...}```, but whatever makes it work is fine with me. ```${...}``` might be the better choice as all the required parsing exists already, but then my new algorithm has to kick in before the usual Spring-stuff.

Here's what I have so far:

```@Configuration
public class BaseAppConfig {

  @Bean
  public static PropertySourcesPlaceholderConfigurer properties(Environment environment) throws IOException {
    String env = getEnvProperty(environment);
    PropertySourcesPlaceholderConfigurer configurer = new PropertySourcesPlaceholderConfigurer();
    configurer.setLocations(getPropertiesFiles(env));
    configurer.setIgnoreResourceNotFound(true);
    return configurer;
  }
```

I tried a fancier ```PropertySourcesPlaceholderConfigurer```, but ```convertPropertyValue()``` is never called:

```    PropertySourcesPlaceholderConfigurer configurer = new PropertySourcesPlaceholderConfigurer() {

      @Override
      protected String convertPropertyValue(String originalValue) {
        System.out.println("Parse " + originalValue);
        return super.convertPropertyValue(originalValue);
      }

    };
```

I tried to look into how Spring does its job and it seems that it works with ```PropertyResolver```s. However, I don't see how I could weave one into that.

So how would I solve this?


Here is the accepted answer: Actually it's quite easy once I knew that Spring's ```RandomValuePropertySource``` was working exactly the way I intended.

Within minutes I was able to code a fancy duration configuration like

```connection.connectTimeout=${duration:15s}
```

The missing link then is:

```  @Bean
  public static PropertySourcesPlaceholderConfigurer properties(Environment environment) throws IOException {
    AbstractEnvironment standardEnvironment = ((AbstractEnvironment) environment);
    MutablePropertySources propertySources = standardEnvironment.getPropertySources();
    propertySources.addLast(new DurationValuePropertySource());
  }
```



{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 1, 'CommentCount': 0, 'ContentLicense': 'CC BY-SA 3.0', 'CreationDate': '2016:00:04/01/16', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<java><spring><configuration><properties-file>', 'Title': 'PropertySourcesPlaceholderConfigurer With Specific Value Parser', 'ViewCount': 84, 'id': 36349012, 'user_AboutMe': '<p>(my <em>about me</em> is currently blank)</p>\n', 'user_AccountId': 223715.0, 'user_DisplayName': 'sjngm', 'user_Reputation': 12063.0, 'user_Views': 1461.0, 'user_id': 483113.0}}