@TargetSE(valueSE=TYPESE) @RetentionSE(valueSE=RUNTIMESE) @DocumentedSE @InheritedSE public @interface ActiveProfiles
ActiveProfiles はクラスレベルのアノテーションであり、テストクラスの ApplicationContext をロードするときに使用するアクティブな Bean 定義プロファイルを宣言するために使用されます。Spring Framework 4.0 以降、このアノテーションをメタアノテーションとして使用して、カスタム合成アノテーションを作成できます。
SmartContextLoader, MergedContextConfiguration, ContextConfiguration, ActiveProfilesResolver, ApplicationContext, Profile| 修飾子と型 | オプションの要素と説明 |
|---|---|
boolean | inheritProfiles スーパークラスの Bean 定義プロファイルを継承するかどうか。 |
StringSE[] | profiles アクティブにする Bean 定義プロファイル。 |
ClassSE<? extends ActiveProfilesResolver> | resolver プログラムでアクティブな Bean 定義プロファイルを解決するために使用する ActiveProfilesResolver の型。 |
StringSE[] | valueprofiles() のエイリアス。 |
@AliasFor(value="profiles") public abstract StringSE[] value
profiles() のエイリアス。 この属性は、profiles() と組み合わせて使用することはできませんが、profiles() の代わりに使用することができます。
public abstract ClassSE<? extends ActiveProfilesResolver> resolver
ActiveProfilesResolver の型。ActiveProfilesResolverpublic abstract boolean inheritProfiles
デフォルト値は true です。つまり、テストクラスは、テストスーパークラスによって定義された Bean 定義プロファイルを継承します。具体的には、テストクラスの Bean 定義プロファイルは、テストスーパークラスによって定義された Bean 定義プロファイルのリストに追加されます。サブクラスには、Bean 定義プロファイルのリストを拡張するオプションがあります。
inheritProfiles が false に設定されている場合、テストクラスの Bean 定義プロファイルは、スーパークラスによって定義された Bean 定義プロファイルをシャドウし、効果的に置き換えます。
次の例では、BaseTest の ApplicationContext は、「ベース」Bean 定義プロファイルのみを使用してロードされます。「拡張」プロファイルで定義された Bean はロードされません。対照的に、ExtendedTest の ApplicationContext は、「ベース」 および 「拡張」Bean 定義プロファイルを使用してロードされます。
@ActiveProfiles("base")
@ContextConfiguration
public class BaseTest {
// ...
}
@ActiveProfiles("extended")
@ContextConfiguration
public class ExtendedTest extends BaseTest {
// ...
}
メモ: @ActiveProfiles は、パスベースのリソースロケーションまたはアノテーション付きクラスから ApplicationContext をロードするときに使用できます。
ContextConfiguration.locations(), ContextConfiguration.classes(), ContextConfiguration.inheritLocations()