注释类型 TestConstructor
@Target(TYPE) @Retention(RUNTIME) @Documented @Inherited public @interface TestConstructor
@TestConstructor
is a type-level annotation that is used to configure how the parameters of a test class constructor are autowired from components in the test'sApplicationContext
.If
@TestConstructor
is not present or meta-present on a test class, the default test constructor autowire mode will be used. SeeTEST_CONSTRUCTOR_AUTOWIRE_MODE_PROPERTY_NAME
for details on how to change the default mode. Note, however, that a local declaration of@Autowired
on a constructor takes precedence over both@TestConstructor
and the default mode.This annotation may be used as a meta-annotation to create custom composed annotations.
As of Spring Framework 5.2, this annotation is only supported in conjunction with the
SpringExtension
for use with JUnit Jupiter. Note that theSpringExtension
is often automatically registered for you — for example, when using annotations such as@SpringJUnitConfig
and@SpringJUnitWebConfig
or various test-related annotations from Spring Boot Test.- 从以下版本开始:
- 5.2
- 作者:
- Sam Brannen
- 另请参阅:
@Autowired
,SpringExtension
,@SpringJUnitConfig
,@SpringJUnitWebConfig
,@ContextConfiguration
,@ContextHierarchy
,@ActiveProfiles
,@TestPropertySource
字段概要
字段 修饰符和类型 字段 说明 static String
TEST_CONSTRUCTOR_AUTOWIRE_MODE_PROPERTY_NAME
JVM system property used to change the default test constructor autowire mode: "spring.test.constructor.autowire.mode".
必需元素概要
所需元素 修饰符和类型 必需的元素 说明 TestConstructor.AutowireMode
autowireMode
Flag for setting the test constructor autowire mode for the current test class.
字段详细资料
TEST_CONSTRUCTOR_AUTOWIRE_MODE_PROPERTY_NAME
static final String TEST_CONSTRUCTOR_AUTOWIRE_MODE_PROPERTY_NAME
JVM system property used to change the default test constructor autowire mode: "spring.test.constructor.autowire.mode".Acceptable values include enum constants defined in
TestConstructor.AutowireMode
, ignoring case. For example, the default may be changed toTestConstructor.AutowireMode.ALL
by supplying the following JVM system property via the command line.-Dspring.test.constructor.autowire.mode=all
If the property is not set to
ALL
, parameters for test class constructors will be autowired according toTestConstructor.AutowireMode.ANNOTATED
semantics by default.May alternatively be configured via the
SpringProperties
mechanism.- 另请参阅:
autowireMode()
元素详细资料
autowireMode
TestConstructor.AutowireMode autowireMode
Flag for setting the test constructor autowire mode for the current test class.Setting this flag overrides the global default. See
TEST_CONSTRUCTOR_AUTOWIRE_MODE_PROPERTY_NAME
for details on how to change the global default.- 返回:
- an
TestConstructor.AutowireMode
to take precedence over the global default - 另请参阅:
TEST_CONSTRUCTOR_AUTOWIRE_MODE_PROPERTY_NAME
,@Autowired
,TestConstructor.AutowireMode.ALL
,TestConstructor.AutowireMode.ANNOTATED