Skip to content

Commit 55fcad3

Browse files
committed
Merge branch '3.4.x' into 3.5.x
Closes gh-46225
2 parents 8499888 + 5479f5c commit 55fcad3

File tree

2 files changed

+70
-0
lines changed

2 files changed

+70
-0
lines changed

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/metadata/DataSourcePoolMetadataProvidersConfiguration.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
import org.apache.commons.dbcp2.BasicDataSourceMXBean;
2525
import org.apache.tomcat.jdbc.pool.jmx.ConnectionPoolMBean;
2626

27+
import org.springframework.aot.hint.RuntimeHints;
28+
import org.springframework.aot.hint.RuntimeHintsRegistrar;
2729
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
2830
import org.springframework.boot.jdbc.DataSourceUnwrapper;
2931
import org.springframework.boot.jdbc.metadata.CommonsDbcp2DataSourcePoolMetadata;
@@ -33,6 +35,7 @@
3335
import org.springframework.boot.jdbc.metadata.TomcatDataSourcePoolMetadata;
3436
import org.springframework.context.annotation.Bean;
3537
import org.springframework.context.annotation.Configuration;
38+
import org.springframework.context.annotation.ImportRuntimeHints;
3639

3740
/**
3841
* Register the {@link DataSourcePoolMetadataProvider} instances for the supported data
@@ -65,6 +68,7 @@ DataSourcePoolMetadataProvider tomcatPoolDataSourceMetadataProvider() {
6568

6669
@Configuration(proxyBeanMethods = false)
6770
@ConditionalOnClass(HikariDataSource.class)
71+
@ImportRuntimeHints(HikariDataSourcePoolMetadataRuntimeHints.class)
6872
static class HikariPoolDataSourceMetadataProviderConfiguration {
6973

7074
@Bean
@@ -116,4 +120,13 @@ DataSourcePoolMetadataProvider oracleUcpPoolDataSourceMetadataProvider() {
116120

117121
}
118122

123+
static class HikariDataSourcePoolMetadataRuntimeHints implements RuntimeHintsRegistrar {
124+
125+
@Override
126+
public void registerHints(RuntimeHints hints, ClassLoader classLoader) {
127+
hints.reflection().registerType(HikariDataSource.class, (builder) -> builder.withField("pool"));
128+
}
129+
130+
}
131+
119132
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
* Copyright 2012-present the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.boot.autoconfigure.jdbc.metadata;
18+
19+
import java.util.Optional;
20+
21+
import com.zaxxer.hikari.HikariDataSource;
22+
import org.junit.jupiter.api.Test;
23+
24+
import org.springframework.aot.hint.RuntimeHints;
25+
import org.springframework.aot.hint.predicate.RuntimeHintsPredicates;
26+
import org.springframework.boot.autoconfigure.jdbc.metadata.DataSourcePoolMetadataProvidersConfiguration.HikariDataSourcePoolMetadataRuntimeHints;
27+
import org.springframework.boot.autoconfigure.jdbc.metadata.DataSourcePoolMetadataProvidersConfiguration.HikariPoolDataSourceMetadataProviderConfiguration;
28+
import org.springframework.context.annotation.ImportRuntimeHints;
29+
import org.springframework.core.annotation.MergedAnnotations;
30+
31+
import static org.assertj.core.api.Assertions.assertThat;
32+
33+
/**
34+
* Tests for {@link HikariDataSourcePoolMetadataRuntimeHints}.
35+
*
36+
* @author Andy Wilkinson
37+
*/
38+
class HikariDataSourcePoolMetadataRuntimeHintsTests {
39+
40+
@Test
41+
@SuppressWarnings("rawtypes")
42+
void importsRegistrar() {
43+
Optional<Class[]> imported = MergedAnnotations.from(HikariPoolDataSourceMetadataProviderConfiguration.class)
44+
.get(ImportRuntimeHints.class)
45+
.getValue("value", Class[].class);
46+
assertThat(imported).hasValue(new Class[] { HikariDataSourcePoolMetadataRuntimeHints.class });
47+
}
48+
49+
@Test
50+
void registersHints() {
51+
RuntimeHints runtimeHints = new RuntimeHints();
52+
new HikariDataSourcePoolMetadataRuntimeHints().registerHints(runtimeHints, getClass().getClassLoader());
53+
assertThat(HikariDataSource.class).hasDeclaredFields("pool");
54+
assertThat(RuntimeHintsPredicates.reflection().onField(HikariDataSource.class, "pool")).accepts(runtimeHints);
55+
}
56+
57+
}

0 commit comments

Comments
 (0)