Simplify class loading check in pooled DataSource condition
Closes gh-17284
This commit is contained in:
parent
638b4b8186
commit
3ba25b9ee9
|
|
@ -102,23 +102,12 @@ public class DataSourceAutoConfiguration {
|
|||
@Override
|
||||
public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) {
|
||||
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.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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Reference in New Issue