2016-04-01 5 views
0

${...} - 注釈は、他のプロパティへの参照を含んでいる限り、私は理解します。しかし、私はその解析アルゴリズムを拡張したい。ここで特定の値パーサーを持つPropertySourcesPlaceholderConfigurer

は、プロパティファイルです:

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

は、2行目には、まだ動作して15000にreadTimeoutを設定したが、私はライン3作品を作りたいと思います。上記の例では、%{...}を使用していますが、それは何となくうまく動作します。 ${...}は、必要なすべての解析が既に存在するため、より良い選択になるかもしれませんが、私の新しいアルゴリズムは通常のSpring-stuffの前に開始する必要があります。

@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; 
    } 

私はPropertySourcesPlaceholderConfigurer手の込んだを試してみましたが、convertPropertyValue()が呼び出されることはありません:

PropertySourcesPlaceholderConfigurer configurer = new PropertySourcesPlaceholderConfigurer() { 

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

    }; 

私は春がその仕事をしていませんどのように見しようとしましたが、それはそうここ

は、私がこれまでしているものですで動作します。しかし、私はそれをどのように織り込むことができないのか分かりません。

どうすればこの問題を解決できますか?

答えて

0

Spring's RandomValuePropertySourceが意図したとおりに正しく動作していたことがわかったら、実際はかなり簡単です。分以内に

が、私はその後、

connection.connectTimeout=${duration:15s} 

ミッシングリンクのような派手な期間の設定をコーディングすることができたです。

@Bean 
    public static PropertySourcesPlaceholderConfigurer properties(Environment environment) throws IOException { 
    AbstractEnvironment standardEnvironment = ((AbstractEnvironment) environment); 
    MutablePropertySources propertySources = standardEnvironment.getPropertySources(); 
    propertySources.addLast(new DurationValuePropertySource()); 
    } 
関連する問題