Context Failure Threshold
从 Spring Framework 6.1 开始,会实施上下文 failure threshold 策略,它有助于避免反复尝试加载一个失败的 ApplicationContext
。默认情况下,失败阈值设置为 1
,这意味着仅尝试一次为给定的上下文缓存键加载一个 ApplicationContext
(请参见 Context Caching)。任何随后尝试为同一上下文缓存键加载 ApplicationContext
的行为,都将立即导致一个 IllegalStateException
,其中带有错误消息,解释该尝试被先发制人地跳过了。这种行为可以通过避免反复尝试加载一个永远无法成功加载的 ApplicationContext
(例如,由于配置错误或缺少外部资源导致上下文无法在当前环境中加载),让各个测试类和测试套件更快地失败。
As of Spring Framework 6.1, a context failure threshold policy is in place which helps
avoid repeated attempts to load a failing ApplicationContext
. By default, the failure
threshold is set to 1
which means that only one attempt will be made to load an
ApplicationContext
for a given context cache key (see
Context Caching). Any
subsequent attempt to load the ApplicationContext
for the same context cache key will
result in an immediate IllegalStateException
with an error message which explains that
the attempt was preemptively skipped. This behavior allows individual test classes and
test suites to fail faster by avoiding repeated attempts to load an ApplicationContext
that will never successfully load — for example, due to a configuration error or a missing
external resource that prevents the context from loading in the current environment.
你可以通过使用带有正整数值命名的 JVM 系统属性 spring.test.context.failure.threshold
从命令行或构建脚本配置上下文失败阈值。或者,你可以通过SpringProperties
机制设置相同的属性。
You can configure the context failure threshold from the command line or a build script
by setting a JVM system property named spring.test.context.failure.threshold
with a
positive integer value. As an alternative, you can set the same property via the
SpringProperties
mechanism.
如果您希望有效禁用上下文失败阈值,则可以将该属性设置为一个非常大的值。例如,您可以通过 |
If you wish to effectively disable the context failure threshold, you can set the
property to a very large value. For example, from the command line you could set the
system property via |