0

Spring の PropertyPlaceholderConfigurer クラスは、プロパティ ファイル全体を読み取り、すべてのプレースホルダーを自動的に解決できますか? これを行う通常の方法は、PropertyPlaceholderConfigurer Bean を作成し、アプリケーション コンテキストの起動時にこれを行うことですが、コンテキストを起動する前にこれを行う必要がある状況にあります。

私は次のような便利な方法を望んでいました

// Return filtered properties from user input file
Properties getProperties(FileInputStream myPropertiesFile);

Spring のドキュメントにはそのようなものはありませんが、それが間違った場所を探しているためなのか、それとも存在しないためなのかはわかりません。

4

1 に答える 1

0

PropertyPlaceholderConfigurerリソースファイルのロードの場所を指定してインスタンスを作成し、Properties見つかったすべてのプロパティを含むインスタンスを作成するだけですか?

その場合、protected潜在的に使用できる方法があります。

/**
 * Return a merged Properties instance containing both the 
 * loaded properties and properties set on this FactoryBean.
 */
protected Properties mergeProperties() throws IOException

したがって、独自のカスタムPropertyPlaceholderConfigurerを作成してから、このメソッドを使用してすべてのプロパティを返すことができます。すなわち

public class MyPropertyPlaceholderConfigurer extends PropertyPlaceholderConfigurer {

    public Properties getAllProperties() throws IOException {
        return super.mergeProperties();
    }
}

これを行うにはもっと効率的な方法があるかもしれませんが、現時点では見つかりませんでした。私が何か他のものを見つけたらあなたに知らせます。

于 2012-08-14T21:13:49.183 に答える