diff --git a/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc b/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc index 1da848b1dd..2bc75548af 100644 --- a/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc +++ b/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc @@ -58,6 +58,9 @@ content into your application; rather pick only the properties that you need. # AUTO-CONFIGURATION spring.autoconfigure.exclude= # Auto-configuration classes to exclude. + # SPRING CORE + spring.beaninfo.ignore=true # Skip search of BeanInfo classes. + # SPRING CACHE ({sc-spring-boot-autoconfigure}/cache/CacheProperties.{sc-ext}[CacheProperties]) spring.cache.cache-names= # Comma-separated list of cache names to create if supported by the underlying cache manager. spring.cache.ehcache.config= # The location of the configuration file to use to initialize EhCache. diff --git a/spring-boot/src/main/java/org/springframework/boot/context/config/ConfigFileApplicationListener.java b/spring-boot/src/main/java/org/springframework/boot/context/config/ConfigFileApplicationListener.java index d5ae95fbc2..554ef0958c 100644 --- a/spring-boot/src/main/java/org/springframework/boot/context/config/ConfigFileApplicationListener.java +++ b/spring-boot/src/main/java/org/springframework/boot/context/config/ConfigFileApplicationListener.java @@ -30,10 +30,12 @@ import java.util.Set; import org.apache.commons.logging.Log; import org.springframework.beans.BeansException; +import org.springframework.beans.CachedIntrospectionResults; import org.springframework.beans.factory.config.BeanFactoryPostProcessor; import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; import org.springframework.boot.SpringApplication; import org.springframework.boot.bind.PropertiesConfigurationFactory; +import org.springframework.boot.bind.RelaxedPropertyResolver; import org.springframework.boot.context.event.ApplicationEnvironmentPreparedEvent; import org.springframework.boot.context.event.ApplicationPreparedEvent; import org.springframework.boot.env.EnumerableCompositePropertySource; @@ -165,9 +167,21 @@ public class ConfigFileApplicationListener implements EnvironmentPostProcessor, public void postProcessEnvironment(ConfigurableEnvironment environment, SpringApplication application) { addPropertySources(environment, application.getResourceLoader()); + configureIgnoreBeanInfo(environment); bindToSpringApplication(environment, application); } + private void configureIgnoreBeanInfo(ConfigurableEnvironment environment) { + if (System.getProperty( + CachedIntrospectionResults.IGNORE_BEANINFO_PROPERTY_NAME) == null) { + RelaxedPropertyResolver resolver = new RelaxedPropertyResolver(environment, + "spring.beaninfo."); + Boolean ignore = resolver.getProperty("ignore", Boolean.class, Boolean.TRUE); + System.setProperty(CachedIntrospectionResults.IGNORE_BEANINFO_PROPERTY_NAME, + ignore.toString()); + } + } + private void onApplicationPreparedEvent(ApplicationEvent event) { this.logger.replayTo(ConfigFileApplicationListener.class); addPostProcessors(((ApplicationPreparedEvent) event).getApplicationContext()); diff --git a/spring-boot/src/main/resources/META-INF/additional-spring-configuration-metadata.json b/spring-boot/src/main/resources/META-INF/additional-spring-configuration-metadata.json index 8a98e4b2a8..65c48be7c9 100644 --- a/spring-boot/src/main/resources/META-INF/additional-spring-configuration-metadata.json +++ b/spring-boot/src/main/resources/META-INF/additional-spring-configuration-metadata.json @@ -96,6 +96,13 @@ "sourceType": "org.springframework.boot.context.ContextIdApplicationContextInitializer", "description": "Application index." }, + { + "name": "spring.beaninfo.ignore", + "type": "java.lang.Boolean", + "sourceType": "org.springframework.boot.context.config.ConfigFileApplicationListener", + "description": "Skip search of BeanInfo classes.", + "defaultValue": true + }, { "name": "spring.config.name", "type": "java.lang.String", diff --git a/spring-boot/src/test/java/org/springframework/boot/context/config/ConfigFileApplicationListenerTests.java b/spring-boot/src/test/java/org/springframework/boot/context/config/ConfigFileApplicationListenerTests.java index 3acac650dd..3125882792 100644 --- a/spring-boot/src/test/java/org/springframework/boot/context/config/ConfigFileApplicationListenerTests.java +++ b/spring-boot/src/test/java/org/springframework/boot/context/config/ConfigFileApplicationListenerTests.java @@ -40,6 +40,7 @@ import org.junit.Test; import org.junit.rules.ExpectedException; import org.slf4j.LoggerFactory; +import org.springframework.beans.CachedIntrospectionResults; import org.springframework.boot.Banner; import org.springframework.boot.SpringApplication; import org.springframework.boot.context.config.ConfigFileApplicationListener.ConfigurationPropertySources; @@ -111,6 +112,7 @@ public class ConfigFileApplicationListenerTests { System.clearProperty("the.property"); System.clearProperty("spring.config.location"); System.clearProperty("spring.main.banner-mode"); + System.clearProperty(CachedIntrospectionResults.IGNORE_BEANINFO_PROPERTY_NAME); } @Test @@ -743,6 +745,26 @@ public class ConfigFileApplicationListenerTests { assertThat(property, equalTo("baz")); } + @Test + public void setIgnoreBeanInfoPropertyByDefault() throws Exception { + this.initializer.setSearchNames("testproperties"); + this.initializer.postProcessEnvironment(this.environment, this.application); + String property = System + .getProperty(CachedIntrospectionResults.IGNORE_BEANINFO_PROPERTY_NAME); + assertThat(property, equalTo("true")); + } + + @Test + public void disableIgnoreBeanInfoProperty() throws Exception { + this.initializer.setSearchNames("testproperties"); + EnvironmentTestUtils.addEnvironment(this.environment, + "spring.beaninfo.ignore=false"); + this.initializer.postProcessEnvironment(this.environment, this.application); + String property = System + .getProperty(CachedIntrospectionResults.IGNORE_BEANINFO_PROPERTY_NAME); + assertThat(property, equalTo("false")); + } + private static Matcher containsPropertySource( final String sourceName) { return new TypeSafeDiagnosingMatcher() {