Skip to content

Commit 9fbb664

Browse files
committed
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
1 parent e937b2e commit 9fbb664

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/autoconfigure/DevToolsDataSourceAutoConfiguration.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,11 +180,11 @@ public ConfigurationPhase getConfigurationPhase() {
180180
@Override
181181
public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) {
182182
ConditionMessage.Builder message = ConditionMessage.forCondition("DevTools DataSource Condition");
183-
String[] dataSourceBeanNames = context.getBeanFactory().getBeanNamesForType(DataSource.class);
183+
String[] dataSourceBeanNames = context.getBeanFactory().getBeanNamesForType(DataSource.class, true, false);
184184
if (dataSourceBeanNames.length != 1) {
185185
return ConditionOutcome.noMatch(message.didNotFind("a single DataSource bean").atAll());
186186
}
187-
if (context.getBeanFactory().getBeanNamesForType(DataSourceProperties.class).length != 1) {
187+
if (context.getBeanFactory().getBeanNamesForType(DataSourceProperties.class, true, false).length != 1) {
188188
return ConditionOutcome.noMatch(message.didNotFind("a single DataSourceProperties bean").atAll());
189189
}
190190
BeanDefinition dataSourceDefinition = context.getRegistry().getBeanDefinition(dataSourceBeanNames[0]);

0 commit comments

Comments
 (0)