Skip to content

Commit

Permalink
Skip BeanInfo class search by default
Browse files Browse the repository at this point in the history
Set `CachedIntrospectionResults.IGNORE_BEANINFO_PROPERTY_NAME` by
default to improve startup performance. The `spring.beaninfo.ignore`
property can be set in `application.properties` if BeanInfo classes
should be searched.

Fixes spring-projectsgh-4390
  • Loading branch information
philwebb committed Nov 5, 2015
1 parent d88210f commit c94cb1f
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,12 @@
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;
Expand Down Expand Up @@ -165,9 +167,21 @@ private void onApplicationEnvironmentPreparedEvent(
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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
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;
Expand Down Expand Up @@ -111,6 +112,7 @@ public void cleanup() {
System.clearProperty("the.property");
System.clearProperty("spring.config.location");
System.clearProperty("spring.main.banner-mode");
System.clearProperty(CachedIntrospectionResults.IGNORE_BEANINFO_PROPERTY_NAME);
}

@Test
Expand Down Expand Up @@ -743,6 +745,26 @@ public void profileSubDocumentInDifferentProfileSpecificFile() throws Exception
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<? super ConfigurableEnvironment> containsPropertySource(
final String sourceName) {
return new TypeSafeDiagnosingMatcher<ConfigurableEnvironment>() {
Expand Down

0 comments on commit c94cb1f

Please sign in to comment.