gpt4 book ai didi

java - 如何在测试中启用Spring的自动配置报告?

转载 作者:塔克拉玛干 更新时间:2023-11-03 03:32:23 25 4
gpt4 key购买 nike

我刚刚发现 Spring 有一个 Debug模式,可以深入了解自动配置。对于服务器,可以通过将 --debug 作为应用程序参数传递来启用它。

有没有办法为测试启用 Debug模式(使用 SpringJUnit4ClassRunner 执行)?


如果自动配置报告正常工作,它应该打印如下输出:

=========================
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 设置一个 debug 属性,然后打开自动配置报告。您可以在测试中使用例如 @TestPropertySource 在您的测试类中执行相同的操作:

@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(Application.class)
@TestPropertySource(properties = "debug=true")
public class YourTests {
// …
}

关于java - 如何在测试中启用Spring的自动配置报告?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38189191/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com