Skip BeanInfo class search by default
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 gh-4390
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -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());
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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<? super ConfigurableEnvironment> containsPropertySource(
|
||||
final String sourceName) {
|
||||
return new TypeSafeDiagnosingMatcher<ConfigurableEnvironment>() {
|
||||
|
||||
Reference in New Issue
Block a user