@ContextCustomizerFactories
@ContextCustomizerFactories
是一种注释,可以应用于测试类以注册用于特定测试类、其子类及其嵌套类的 ContextCustomizerFactory
实现。如果您希望全局注册工厂,您应该通过ContextCustomizerFactory
Configuration 中描述的自动发现机制进行注册。
@ContextCustomizerFactories
is an annotation that can be applied to a test class to
register ContextCustomizerFactory
implementations for the particular test class, its
subclasses, and its nested classes. If you wish to register a factory globally, you
should register it via the automatic discovery mechanism described in
ContextCustomizerFactory
Configuration.
以下示例演示如何注册两个 ContextCustomizerFactory
实现:
The following example shows how to register two ContextCustomizerFactory
implementations:
- Java
-
@ContextConfiguration @ContextCustomizerFactories({CustomContextCustomizerFactory.class, AnotherContextCustomizerFactory.class}) (1) class CustomContextCustomizerFactoryTests { // class body... }
1 | Register two ContextCustomizerFactory implementations.
|
2 | Register two ContextCustomizerFactory implementations. |
默认情况下,@ContextCustomizerFactories
提供从超类或封闭类继承工厂的支持。有关示例和进一步的详细信息,请参见 @Nested
test class configuration 和https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/test/context/ContextCustomizerFactories.html[@ContextCustomizerFactories
] javadoc。
By default, @ContextCustomizerFactories
provides support for inheriting factories from
superclasses or enclosing classes. See
@Nested
test class configuration and the
@ContextCustomizerFactories
javadoc for an example and further details.