2016-07-04 13 views
8

Tôi vừa phát hiện ra rằng Spring có chế độ gỡ lỗi, chế độ này cung cấp thông tin chi tiết về cấu hình tự động. Đối với máy chủ, có thể bật máy chủ bằng cách chuyển --debug làm thông số ứng dụng.Làm cách nào để bật báo cáo cấu hình tự động của Spring trong các thử nghiệm?

Có cách nào để bật chế độ gỡ lỗi cũng cho thử nghiệm (được thực hiện với SpringJUnit4ClassRunner) không?


Nếu báo cáo tự động cấu hình đang làm việc, nó sẽ in một số đầu ra như thế này:

========================= 
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 

Trả lời

15

--debug thiết lập một tài sản mà sau đó chuyển vào báo cáo tự động cấu hình debug. Bạn có thể làm tương tự trong thử nghiệm của mình bằng cách sử dụng, ví dụ: @TestPropertySource trên lớp thử nghiệm của bạn:

@RunWith(SpringJUnit4ClassRunner.class) 
@SpringApplicationConfiguration(Application.class) 
@TestPropertySource(properties = "debug=true") 
public class YourTests { 
    // … 
} 
Các vấn đề liên quan