All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.trang.druid.actuate.autoconfigure.DruidDataSourceMetadataProviderConfiguration Maven / Gradle / Ivy

There is a newer version: 1.1.10.2
Show newest version
package com.github.trang.druid.actuate.autoconfigure;

import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.jdbc.metadata.DataSourcePoolMetadataProvider;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.alibaba.druid.pool.DruidDataSource;
import com.github.trang.druid.actuate.DruidDataSourcePoolMetadata;

/**
 * Druid Metadata 自动配置,适用于 Metrics,默认开启
 *
 * @author trang
 */
@Configuration
@ConditionalOnClass(DruidDataSource.class)
public class DruidDataSourceMetadataProviderConfiguration {

    @Bean
    @ConditionalOnMissingBean
    public DataSourcePoolMetadataProvider dataSourcePoolMetadataProvider() {
        return (dataSource) -> {
            if (dataSource instanceof DruidDataSource) {
                return new DruidDataSourcePoolMetadata((DruidDataSource) dataSource);
            }
            return null;
        };
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy