Merge branch '2.3.x' into 2.4.x
Closes gh-24841
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2020 the original author or authors.
|
||||
* Copyright 2012-2021 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.
|
||||
@@ -20,10 +20,12 @@ import java.sql.SQLException;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import com.zaxxer.hikari.HikariConfigMXBean;
|
||||
import com.zaxxer.hikari.HikariDataSource;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.apache.tomcat.jdbc.pool.DataSourceProxy;
|
||||
import org.apache.tomcat.jdbc.pool.PoolConfiguration;
|
||||
|
||||
import org.springframework.beans.factory.ObjectProvider;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
@@ -62,7 +64,8 @@ class DataSourceJmxConfiguration {
|
||||
}
|
||||
|
||||
private void validateMBeans() {
|
||||
HikariDataSource hikariDataSource = DataSourceUnwrapper.unwrap(this.dataSource, HikariDataSource.class);
|
||||
HikariDataSource hikariDataSource = DataSourceUnwrapper.unwrap(this.dataSource, HikariConfigMXBean.class,
|
||||
HikariDataSource.class);
|
||||
if (hikariDataSource != null && hikariDataSource.isRegisterMbeans()) {
|
||||
this.mBeanExporter.ifUnique((exporter) -> exporter.addExcludedBean("dataSource"));
|
||||
}
|
||||
@@ -79,7 +82,8 @@ class DataSourceJmxConfiguration {
|
||||
@Bean
|
||||
@ConditionalOnMissingBean(name = "dataSourceMBean")
|
||||
Object dataSourceMBean(DataSource dataSource) {
|
||||
DataSourceProxy dataSourceProxy = DataSourceUnwrapper.unwrap(dataSource, DataSourceProxy.class);
|
||||
DataSourceProxy dataSourceProxy = DataSourceUnwrapper.unwrap(dataSource, PoolConfiguration.class,
|
||||
DataSourceProxy.class);
|
||||
if (dataSourceProxy != null) {
|
||||
try {
|
||||
return dataSourceProxy.createPool().getJmxPool();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2020 the original author or authors.
|
||||
* Copyright 2012-2021 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.
|
||||
@@ -16,10 +16,13 @@
|
||||
|
||||
package org.springframework.boot.autoconfigure.jdbc.metadata;
|
||||
|
||||
import com.zaxxer.hikari.HikariConfigMXBean;
|
||||
import com.zaxxer.hikari.HikariDataSource;
|
||||
import oracle.jdbc.OracleConnection;
|
||||
import oracle.ucp.jdbc.PoolDataSource;
|
||||
import org.apache.commons.dbcp2.BasicDataSource;
|
||||
import org.apache.commons.dbcp2.BasicDataSourceMXBean;
|
||||
import org.apache.tomcat.jdbc.pool.jmx.ConnectionPoolMBean;
|
||||
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
import org.springframework.boot.jdbc.DataSourceUnwrapper;
|
||||
@@ -50,7 +53,7 @@ public class DataSourcePoolMetadataProvidersConfiguration {
|
||||
DataSourcePoolMetadataProvider tomcatPoolDataSourceMetadataProvider() {
|
||||
return (dataSource) -> {
|
||||
org.apache.tomcat.jdbc.pool.DataSource tomcatDataSource = DataSourceUnwrapper.unwrap(dataSource,
|
||||
org.apache.tomcat.jdbc.pool.DataSource.class);
|
||||
ConnectionPoolMBean.class, org.apache.tomcat.jdbc.pool.DataSource.class);
|
||||
if (tomcatDataSource != null) {
|
||||
return new TomcatDataSourcePoolMetadata(tomcatDataSource);
|
||||
}
|
||||
@@ -67,7 +70,8 @@ public class DataSourcePoolMetadataProvidersConfiguration {
|
||||
@Bean
|
||||
DataSourcePoolMetadataProvider hikariPoolDataSourceMetadataProvider() {
|
||||
return (dataSource) -> {
|
||||
HikariDataSource hikariDataSource = DataSourceUnwrapper.unwrap(dataSource, HikariDataSource.class);
|
||||
HikariDataSource hikariDataSource = DataSourceUnwrapper.unwrap(dataSource, HikariConfigMXBean.class,
|
||||
HikariDataSource.class);
|
||||
if (hikariDataSource != null) {
|
||||
return new HikariDataSourcePoolMetadata(hikariDataSource);
|
||||
}
|
||||
@@ -84,7 +88,8 @@ public class DataSourcePoolMetadataProvidersConfiguration {
|
||||
@Bean
|
||||
DataSourcePoolMetadataProvider commonsDbcp2PoolDataSourceMetadataProvider() {
|
||||
return (dataSource) -> {
|
||||
BasicDataSource dbcpDataSource = DataSourceUnwrapper.unwrap(dataSource, BasicDataSource.class);
|
||||
BasicDataSource dbcpDataSource = DataSourceUnwrapper.unwrap(dataSource, BasicDataSourceMXBean.class,
|
||||
BasicDataSource.class);
|
||||
if (dbcpDataSource != null) {
|
||||
return new CommonsDbcp2DataSourcePoolMetadata(dbcpDataSource);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user