|
|
|
@ -16,14 +16,22 @@
|
|
|
|
|
|
|
|
|
|
package org.springframework.boot.autoconfigure.jdbc;
|
|
|
|
|
|
|
|
|
|
import java.sql.SQLException;
|
|
|
|
|
|
|
|
|
|
import javax.annotation.PostConstruct;
|
|
|
|
|
import javax.sql.DataSource;
|
|
|
|
|
|
|
|
|
|
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.springframework.beans.factory.ObjectProvider;
|
|
|
|
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
|
|
|
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
|
|
|
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
|
|
|
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnSingleCandidate;
|
|
|
|
|
import org.springframework.context.annotation.Bean;
|
|
|
|
|
import org.springframework.context.annotation.Configuration;
|
|
|
|
|
import org.springframework.jmx.export.MBeanExporter;
|
|
|
|
|
|
|
|
|
@ -36,6 +44,8 @@ import org.springframework.jmx.export.MBeanExporter;
|
|
|
|
|
@ConditionalOnProperty(prefix = "spring.jmx", name = "enabled", havingValue = "true", matchIfMissing = true)
|
|
|
|
|
class DataSourceJmxConfiguration {
|
|
|
|
|
|
|
|
|
|
private static final Log logger = LogFactory.getLog(DataSourceJmxConfiguration.class);
|
|
|
|
|
|
|
|
|
|
@Configuration
|
|
|
|
|
@ConditionalOnClass(HikariDataSource.class)
|
|
|
|
|
@ConditionalOnSingleCandidate(HikariDataSource.class)
|
|
|
|
@ -61,4 +71,26 @@ class DataSourceJmxConfiguration {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Configuration
|
|
|
|
|
@ConditionalOnProperty(prefix = "spring.datasource", name = "jmx-enabled")
|
|
|
|
|
@ConditionalOnClass(name = "org.apache.tomcat.jdbc.pool.DataSourceProxy")
|
|
|
|
|
@ConditionalOnSingleCandidate(DataSource.class)
|
|
|
|
|
static class TomcatDataSourceJmxConfiguration {
|
|
|
|
|
|
|
|
|
|
@Bean
|
|
|
|
|
@ConditionalOnMissingBean(name = "dataSourceMBean")
|
|
|
|
|
public Object dataSourceMBean(DataSource dataSource) {
|
|
|
|
|
if (dataSource instanceof DataSourceProxy) {
|
|
|
|
|
try {
|
|
|
|
|
return ((DataSourceProxy) dataSource).createPool().getJmxPool();
|
|
|
|
|
}
|
|
|
|
|
catch (SQLException ex) {
|
|
|
|
|
logger.warn("Cannot expose DataSource to JMX (could not connect)");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|