[英]How to enable Spring's auto-configuration report in tests?
I just found out that Spring has a debug mode, which gives insights on the auto-configuration. 我刚刚发现Spring有一个调试模式,它可以提供有关自动配置的见解。 For a server, it can be enabled by passing --debug
as an application parameter. 对于服务器,可以通过将--debug
作为应用程序参数传递来启用它。
Is there a way to enable the debug mode also for tests (executed with the SpringJUnit4ClassRunner
)? 有没有办法为测试启用调试模式(使用SpringJUnit4ClassRunner
执行)?
If the auto-configuration report is working, it should print some output like this: 如果自动配置报告正在运行,它应该打印一些输出,如下所示:
=========================
AUTO-CONFIGURATION REPORT
=========================
Positive matches:
-----------------
ConfigServiceBootstrapConfiguration#configServicePropertySource matched
- matched (OnPropertyCondition)
ConfigurationPropertiesRebinderAutoConfiguration matched
- @ConditionalOnBean (types: org.springframework.boot.context.properties.ConfigurationPropertiesBindingPostProcessor; SearchStrategy: all) found the following [org.springframework.boot.context.properties.ConfigurationPropertiesBindingPostProcessor] (OnBeanCondition)
ConfigurationPropertiesRebinderAutoConfiguration#configurationPropertiesBeans matched
- @ConditionalOnMissingBean (types: org.springframework.cloud.context.properties.ConfigurationPropertiesBeans; SearchStrategy: current) found no beans (OnBeanCondition)
ConfigurationPropertiesRebinderAutoConfiguration#configurationPropertiesRebinder matched
- @ConditionalOnMissingBean (types: org.springframework.cloud.context.properties.ConfigurationPropertiesRebinder; SearchStrategy: current) found no beans (OnBeanCondition)
EncryptionBootstrapConfiguration matched
- @ConditionalOnClass classes found: org.springframework.security.crypto.encrypt.TextEncryptor (OnClassCondition)
PropertyPlaceholderAutoConfiguration#propertySourcesPlaceholderConfigurer matched
- @ConditionalOnMissingBean (types: org.springframework.context.support.PropertySourcesPlaceholderConfigurer; SearchStrategy: current) found no beans (OnBeanCondition)
Negative matches:
-----------------
ConfigServiceBootstrapConfiguration.RetryConfiguration did not match
- required @ConditionalOnClass classes not found: org.springframework.retry.annotation.Retryable,org.aspectj.lang.annotation.Aspect (OnClassCondition)
DiscoveryClientConfigServiceBootstrapConfiguration did not match
- @ConditionalOnProperty missing required properties spring.cloud.config.discovery.enabled (OnPropertyCondition)
EncryptionBootstrapConfiguration.RsaEncryptionConfiguration did not match
- @ConditionalOnClass classes found: org.springframework.security.rsa.crypto.RsaSecretEncryptor (OnClassCondition)
- Keystore nor key found in Environment (EncryptionBootstrapConfiguration.KeyCondition)
EncryptionBootstrapConfiguration.VanillaEncryptionConfiguration did not match
- required @ConditionalOnMissing classes found: org.springframework.security.rsa.crypto.RsaSecretEncryptor (OnClassCondition)
EurekaDiscoveryClientConfigServiceBootstrapConfiguration did not match
- @ConditionalOnClass classes found: org.springframework.cloud.config.client.ConfigServicePropertySourceLocator (OnClassCondition)
- @ConditionalOnProperty missing required properties spring.cloud.config.discovery.enabled (OnPropertyCondition)
Exclusions:
-----------
None
Unconditional classes:
----------------------
None
--debug
sets a debug
property which then switches on the auto-configuration report. --debug
设置一个debug
属性,然后打开自动配置报告。 You can do the same in your test using, for example, @TestPropertySource
on your test class: 您可以在测试中使用(例如)测试类上的@TestPropertySource
执行相同的操作:
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(Application.class)
@TestPropertySource(properties = "debug=true")
public class YourTests {
// …
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.