Commit 3ba25b9e authored by Andy Wilkinson's avatar Andy Wilkinson

Simplify class loading check in pooled DataSource condition

Closes gh-17284
parent 638b4b81
...@@ -102,23 +102,12 @@ public class DataSourceAutoConfiguration { ...@@ -102,23 +102,12 @@ public class DataSourceAutoConfiguration {
@Override @Override
public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) { public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) {
ConditionMessage.Builder message = ConditionMessage.forCondition("PooledDataSource"); ConditionMessage.Builder message = ConditionMessage.forCondition("PooledDataSource");
if (getDataSourceClassLoader(context) != null) { if (DataSourceBuilder.findType(context.getClassLoader()) != null) {
return ConditionOutcome.match(message.foundExactly("supported DataSource")); return ConditionOutcome.match(message.foundExactly("supported DataSource"));
} }
return ConditionOutcome.noMatch(message.didNotFind("supported DataSource").atAll()); return ConditionOutcome.noMatch(message.didNotFind("supported DataSource").atAll());
} }
/**
* Returns the class loader for the {@link DataSource} class. Used to ensure that
* the driver class can actually be loaded by the data source.
* @param context the condition context
* @return the class loader
*/
private ClassLoader getDataSourceClassLoader(ConditionContext context) {
Class<?> dataSourceClass = DataSourceBuilder.findType(context.getClassLoader());
return (dataSourceClass != null) ? dataSourceClass.getClassLoader() : null;
}
} }
/** /**
......
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