T
- ソース型 public abstract class PropertySource<T> extends ObjectSE
T
の可能性があります。例には、Properties
SE オブジェクト、Map
SE オブジェクト、ServletContext
および ServletConfig
オブジェクト(init パラメーターへのアクセス用)が含まれます。PropertySource
型階層を調べて、提供されている実装を確認してください。PropertySource
オブジェクトは通常、単独で使用されるのではなく、PropertySources
オブジェクトを通じて使用されます。PropertySources
オブジェクトは、プロパティソースを集約し、PropertySources
のセット全体で優先順位ベースの検索を実行できる PropertyResolver
実装と連携します。
PropertySource
ID は、カプセル化されたプロパティのコンテンツに基づいて決定されるのではなく、PropertySource
のみの name
に基づいて決定されます。これは、コレクションコンテキストで PropertySource
オブジェクトを操作するのに便利です。詳細については、MutablePropertySources
および named(String)
および toString()
メソッドの操作を参照してください。
@Configuration
クラスを使用する場合、@PropertySource
アノテーションは、プロパティソースを囲む Environment
に追加する便利で宣言的な方法を提供することに注意してください。
PropertySources
, PropertyResolver
, PropertySourcesPropertyResolver
, MutablePropertySources
, PropertySource
修飾子と型 | クラスと説明 |
---|---|
static class | PropertySource.StubPropertySource 実際のプロパティソースをアプリケーションコンテキストの作成時に積極的に初期化できない場合にプレースホルダーとして使用される PropertySource 。 |
コンストラクターと説明 |
---|
PropertySource(StringSE name) 指定された名前と、基になるソースとして新しい Object インスタンスを使用して、新しい PropertySource を作成します。 |
PropertySource(StringSE name, T source) 指定された名前とソースオブジェクトで新しい PropertySource を作成します。 |
修飾子と型 | メソッドと説明 |
---|---|
boolean | containsProperty(StringSE name) この PropertySource に指定された名前が含まれているかどうかを返します。 |
boolean | equals(ObjectSE other) この PropertySource オブジェクトは、次の場合に指定されたオブジェクトと等しくなります。これらが同じインスタンスであり、両方のオブジェクトの name プロパティが等しい場合 |
StringSE | getName() この PropertySource の名前を返します。 |
abstract ObjectSE | getProperty(StringSE name) 指定された名前に関連付けられた値を返します。見つからない場合は null を返します。 |
T | getSource() この PropertySource の基になるソースオブジェクトを返します。 |
int | hashCode() この PropertySource オブジェクトの name プロパティから派生したハッシュコードを返します。 |
static PropertySource<?> | named(StringSE name) コレクションの比較のみを目的とした PropertySource 実装を返します。 |
StringSE | toString() 現在のログレベルにデバッグが含まれていない場合は、簡潔な出力(型と名前)を生成します。 |
cloneSE, finalizeSE, getClassSE, notifySE, notifyAllSE, waitSE, waitSE, waitSE
protected final Log logger
protected final StringSE name
protected final T source
public PropertySource(StringSE name, T source)
PropertySource
を作成します。name
- 関連する名前 source
- ソースオブジェクト public PropertySource(StringSE name)
Object
インスタンスを使用して、新しい PropertySource
を作成します。実際のソースを照会せず、ハードコードされた値を返す匿名実装を作成する場合のテストシナリオでしばしば役立ちます。
public StringSE getName()
PropertySource
の名前を返します。public T getSource()
PropertySource
の基になるソースオブジェクトを返します。public boolean containsProperty(StringSE name)
PropertySource
に指定された名前が含まれているかどうかを返します。 この実装は、getProperty(String)
からの null
戻り値をチェックするだけです。サブクラスは、可能であれば、より効率的なアルゴリズムを実装したい場合があります。
name
- 検索するプロパティ名 @Nullable public abstract ObjectSE getProperty(StringSE name)
null
を返します。name
- 検索するプロパティ PropertyResolver.getRequiredProperty(String)
public boolean equals(@Nullable ObjectSE other)
PropertySource
オブジェクトは指定されたオブジェクトと同等です。name
プロパティが等しい name
以外のプロパティは評価されません。
public int hashCode()
PropertySource
オブジェクトの name
プロパティから派生したハッシュコードを返します。ObjectSE
の hashCodeSE
public StringSE toString()
この変数の冗長性は、システムプロパティや環境変数などのプロパティソースに任意の数のプロパティペアが含まれている可能性があり、読み取りが困難な例外やログメッセージにつながる可能性があるため便利です。
ObjectSE
の toStringSE
Log.isDebugEnabled()
public static PropertySource<?> named(StringSE name)
PropertySource
実装を返します。 主に内部使用のためですが、PropertySource
オブジェクトのコレクションを指定すると、次のように使用できます。
List<PropertySource<?>> sources = new ArrayList<PropertySource<?>>();
sources.add(new MapPropertySource("sourceA", mapA));
sources.add(new MapPropertySource("sourceB", mapB));
assert sources.contains(PropertySource.named("sourceA"));
assert sources.contains(PropertySource.named("sourceB"));
assert !sources.contains(PropertySource.named("sourceC"));
equals(Object)
、hashCode()
、toString()
以外のメソッドが呼び出された場合、返された PropertySource
は UnsupportedOperationException
をスローします。name
- 作成および返される比較 PropertySource
の名前。