@ -183,7 +183,7 @@ public class DataSourceAutoConfiguration implements EnvironmentAware {
}
}
String driverClassName = getDriverClassName ( context . getEnvironment ( ) ,
String driverClassName = getDriverClassName ( context . getEnvironment ( ) ,
context. getClassLoader ( ) ) ;
getDataSourceClassLoader( context ) ) ;
if ( driverClassName = = null ) {
if ( driverClassName = = null ) {
return Outcome . noMatch ( "no database driver" ) ;
return Outcome . noMatch ( "no database driver" ) ;
}
}
@ -200,6 +200,21 @@ public class DataSourceAutoConfiguration implements EnvironmentAware {
return Outcome . noMatch ( "missing database driver " + driverClassName ) ;
return Outcome . noMatch ( "missing database driver " + driverClassName ) ;
}
}
/ * *
* Returns the class loader for the { @link DataSource } class . Used to ensure that
* the driver class can actually be loaded by the data source .
* /
private ClassLoader getDataSourceClassLoader ( ConditionContext context ) {
try {
Class < ? > dataSourceClass = ClassUtils . forName ( getDataSourceClassName ( ) ,
context . getClassLoader ( ) ) ;
return dataSourceClass . getClassLoader ( ) ;
}
catch ( ClassNotFoundException ex ) {
throw new IllegalStateException ( ex ) ;
}
}
private String getDriverClassName ( Environment environment , ClassLoader classLoader ) {
private String getDriverClassName ( Environment environment , ClassLoader classLoader ) {
String driverClassName = environment = = null ? null : environment
String driverClassName = environment = = null ? null : environment
. getProperty ( "spring.database.driverClassName" ) ;
. getProperty ( "spring.database.driverClassName" ) ;