Commit 9fbb664d authored by Andy Wilkinson's avatar Andy Wilkinson

Avoid eager init when evaluating DevToolsDataSourceCondition

Previously, DevToolsDataSourceCondition called
getBeanNamesForType(Class) which could trigger unwanted initialization
of lazy init singletons and objects created by FactoryBeans.

This commit updates DevToolsDataSourceCondition to prohibit eager
init when getting the names of the beans of a particular type.

Fixes gh-20430
parent e937b2e0
...@@ -180,11 +180,11 @@ public class DevToolsDataSourceAutoConfiguration { ...@@ -180,11 +180,11 @@ public class DevToolsDataSourceAutoConfiguration {
@Override @Override
public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) { public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) {
ConditionMessage.Builder message = ConditionMessage.forCondition("DevTools DataSource Condition"); ConditionMessage.Builder message = ConditionMessage.forCondition("DevTools DataSource Condition");
String[] dataSourceBeanNames = context.getBeanFactory().getBeanNamesForType(DataSource.class); String[] dataSourceBeanNames = context.getBeanFactory().getBeanNamesForType(DataSource.class, true, false);
if (dataSourceBeanNames.length != 1) { if (dataSourceBeanNames.length != 1) {
return ConditionOutcome.noMatch(message.didNotFind("a single DataSource bean").atAll()); return ConditionOutcome.noMatch(message.didNotFind("a single DataSource bean").atAll());
} }
if (context.getBeanFactory().getBeanNamesForType(DataSourceProperties.class).length != 1) { if (context.getBeanFactory().getBeanNamesForType(DataSourceProperties.class, true, false).length != 1) {
return ConditionOutcome.noMatch(message.didNotFind("a single DataSourceProperties bean").atAll()); return ConditionOutcome.noMatch(message.didNotFind("a single DataSourceProperties bean").atAll());
} }
BeanDefinition dataSourceDefinition = context.getRegistry().getBeanDefinition(dataSourceBeanNames[0]); BeanDefinition dataSourceDefinition = context.getRegistry().getBeanDefinition(dataSourceBeanNames[0]);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment