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

问题描述 投票:0回答:1

我刚刚发现 Spring Boot 有一个调试模式,它提供了有关自动配置的见解。对于服务器,可以通过传递

--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
java spring spring-boot
1个回答
24
投票

--debug
设置
debug
属性,然后打开自动配置报告。您可以在测试中执行相同的操作,例如在测试类上使用
@TestPropertySource

@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(Application.class)
@TestPropertySource(properties = "debug=true")
public class YourTests {
    // …
}
© www.soinside.com 2019 - 2024. All rights reserved.