Skip to content

UnsupportedDataSourcePropertyException is thrown when attempting to set driverClassName for H2 #26631

@whiskeysierra

Description

@whiskeysierra

After upgrading to 2.5.0, this data source configuration:

spring:
  datasource:
    type: org.h2.jdbcx.JdbcDataSource
    url: jdbc:h2:mem:database
    username: sa
    password: password

fails with the following exception:

Caused by: org.springframework.boot.jdbc.UnsupportedDataSourcePropertyException: No mapping found for driverClassName
	at org.springframework.boot.jdbc.UnsupportedDataSourcePropertyException.throwIf(UnsupportedDataSourcePropertyException.java:36) ~[spring-boot-2.5.0.jar:2.5.0]
	at org.springframework.boot.jdbc.DataSourceBuilder$MappedDataSourceProperties.getMapping(DataSourceBuilder.java:344) ~[spring-boot-2.5.0.jar:2.5.0]
	at org.springframework.boot.jdbc.DataSourceBuilder$MappedDataSourceProperties.set(DataSourceBuilder.java:332) ~[spring-boot-2.5.0.jar:2.5.0]
	at org.springframework.boot.jdbc.DataSourceBuilder.build(DataSourceBuilder.java:179) ~[spring-boot-2.5.0.jar:2.5.0]
	at org.springframework.boot.autoconfigure.jdbc.DataSourceConfiguration$Generic.dataSource(DataSourceConfiguration.java:150) ~[spring-boot-autoconfigure-2.5.0.jar:2.5.0]
	at jdk.internal.reflect.GeneratedMethodAccessor66.invoke(Unknown Source) ~[na:na]
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
	at java.base/java.lang.reflect.Method.invoke(Method.java:566) ~[na:na]
	at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154) ~[spring-beans-5.3.7.jar:5.3.7]
	... 87 common frames omitted

I took a quick look and it seems like the H2DataSourceProperties only supports three properties:

	private static class H2DataSourceProperties extends MappedDataSourceProperties<JdbcDataSource> {

		H2DataSourceProperties() {
			add(DataSourceProperty.URL, JdbcDataSource::getUrl, JdbcDataSource::setUrl);
			add(DataSourceProperty.USERNAME, JdbcDataSource::getUser, JdbcDataSource::setUser);
			add(DataSourceProperty.PASSWORD, JdbcDataSource::getPassword, JdbcDataSource::setPassword);
		}

	}

The driverClassName is not supported, but it will be set by DataSourceProperties#initializeDataSourceBuilder:

	public DataSourceBuilder<?> initializeDataSourceBuilder() {
		return DataSourceBuilder.create(getClassLoader()).type(getType()).driverClassName(determineDriverClassName())
				.url(determineUrl()).username(determineUsername()).password(determinePassword());
	}

Metadata

Metadata

Labels

type: regressionA regression from a previous release

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions