Merge branch '3.4.x'

Closes gh-44999
This commit is contained in:
Andy Wilkinson 2025-04-04 09:28:16 +01:00
commit 219c7ed653
2 changed files with 16 additions and 3 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012-2023 the original author or authors.
* Copyright 2012-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -39,7 +39,10 @@ class HikariJdbcConnectionDetailsBeanPostProcessor extends JdbcConnectionDetails
dataSource.setJdbcUrl(connectionDetails.getJdbcUrl());
dataSource.setUsername(connectionDetails.getUsername());
dataSource.setPassword(connectionDetails.getPassword());
dataSource.setDriverClassName(connectionDetails.getDriverClassName());
String driverClassName = connectionDetails.getDriverClassName();
if (driverClassName != null) {
dataSource.setDriverClassName(connectionDetails.getDriverClassName());
}
return dataSource;
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012-2023 the original author or authors.
* Copyright 2012-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -22,6 +22,7 @@ import org.junit.jupiter.api.Test;
import org.springframework.boot.jdbc.DatabaseDriver;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
/**
* Tests for {@link HikariJdbcConnectionDetailsBeanPostProcessor}.
@ -47,4 +48,13 @@ class HikariJdbcConnectionDetailsBeanPostProcessorTests {
assertThat(dataSource.getDriverClassName()).isEqualTo(DatabaseDriver.POSTGRESQL.getDriverClassName());
}
@Test
void toleratesConnectionDetailsWithNullDriverClassName() {
HikariDataSource dataSource = new HikariDataSource();
dataSource.setDriverClassName(DatabaseDriver.H2.getDriverClassName());
JdbcConnectionDetails connectionDetails = mock(JdbcConnectionDetails.class);
new HikariJdbcConnectionDetailsBeanPostProcessor(null).processDataSource(dataSource, connectionDetails);
assertThat(dataSource.getDriverClassName()).isEqualTo(DatabaseDriver.H2.getDriverClassName());
}
}