I just found out that Spring has a debug mode, which gives insights on the auto-configuration. For a server, it can be enabled by passing --debug
as an application parameter.
Is there a way to enable the debug mode also for tests (executed with the 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
Auto-Configuration in Spring BootThe annotation @EnableAutoConfiguration is used to enable the auto-configuration feature. The @EnableAutoConfiguration annotation enables the auto-configuration of Spring ApplicationContext by scanning the classpath components and registering the beans.
The @EnableAutoConfiguration annotation enables Spring Boot to auto-configure the application context. Therefore, it automatically creates and registers beans based on both the included jar files in the classpath and the beans defined by us.
Test E-mail AutoConfiguration is an Outlook client tool that helps to determine whether Outlook can connect to the Autodiscover service. How to run it? Start Outlook. Press and hold the Ctrl key, right-click the Outlook icon in the notification area, and then click Test E-mail AutoConfiguration.
AutoConfiguration classes are run last (meaning after all regular non-autoconfiguration classes) while the order in which Configuration classes are run is indeterminate (except if we use ordering annotations like @Ordered ) To declare a class as an AutoConfiguration they need to be specified as such in the spring.
--debug
sets a debug
property which then switches on the auto-configuration report. You can do the same in your test using, for example, @TestPropertySource
on your test class:
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(Application.class)
@TestPropertySource(properties = "debug=true")
public class YourTests {
// …
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With