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

org.zodiac.autoconfigure.datasource.jdbc.JdbcDataSourceDruidAutoConfiguration Maven / Gradle / Ivy

There is a newer version: 1.6.8
Show newest version
package org.zodiac.autoconfigure.datasource.jdbc;

import org.springframework.boot.SpringBootConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.PropertySource;
import org.zodiac.autoconfigure.datasource.DataSourceConfigProperties;
import org.zodiac.autoconfigure.datasource.condition.ConditionalOnDataSourceEnabled;
import org.zodiac.commons.constants.SystemPropertiesConstants;

@SpringBootConfiguration
@ConditionalOnDataSourceEnabled
@PropertySource(value = "classpath:/META-INF/config/druid-filters.properties")
@ConditionalOnClass(name = {"org.zodiac.datasource.config.DataSourceConfigInfo", "com.alibaba.druid.pool.DruidDataSource"})
public class JdbcDataSourceDruidAutoConfiguration {

    private DataSourceConfigProperties dataSourceConfigProperties;

    public JdbcDataSourceDruidAutoConfiguration(DataSourceConfigProperties dataSourceConfigProperties) {
        this.dataSourceConfigProperties = dataSourceConfigProperties;
    }

    @Bean
    @ConditionalOnMissingBean
    //@ConfigurationProperties(prefix = SystemPropertiesConstants.Zodiac.SPRING_DATASOURCE_DRUID_FILTER_SLF4J_PREFIX)
    @ConditionalOnProperty(value = SystemPropertiesConstants.Zodiac.SPRING_DATASOURCE_DRUID_FILTER_SLF4J_ENABLED, havingValue = "true")
    protected com.alibaba.druid.filter.logging.Slf4jLogFilter slf4jLogFilter() {
        //return new com.alibaba.druid.filter.logging.Slf4jLogFilter();
        return dataSourceConfigProperties.getDruid().getFilter().getSlf4j();
    }

    @Bean
    @ConditionalOnMissingBean
    //@ConfigurationProperties(prefix = SystemPropertiesConstants.Zodiac.SPRING_DATASOURCE_DRUID_FILTER_STAT_PREFIX)
    @ConditionalOnProperty(value = SystemPropertiesConstants.Zodiac.SPRING_DATASOURCE_DRUID_FILTER_STAT_ENABLED, havingValue = "true")
    protected com.alibaba.druid.filter.stat.StatFilter statFilter() {
        //return new com.alibaba.druid.filter.stat.StatFilter();
        return dataSourceConfigProperties.getDruid().getFilter().getStat();
    }

    @Bean
    @ConditionalOnMissingBean
    //@ConfigurationProperties(prefix = SystemPropertiesConstants.Zodiac.SPRING_DATASOURCE_DRUID_FILTER_WALL_CONFIG_PREFIX)
    @ConditionalOnProperty(value = SystemPropertiesConstants.Zodiac.SPRING_DATASOURCE_DRUID_FILTER_WALL_ENABLED, havingValue = "true")
    protected com.alibaba.druid.wall.WallConfig wallConfig() {
        //return new com.alibaba.druid.wall.WallConfig();
        return dataSourceConfigProperties.getDruid().getFilter().getWallConfig();
    }
 
    @Bean
    @ConditionalOnMissingBean
    //@ConfigurationProperties(prefix = SystemPropertiesConstants.Zodiac.SPRING_DATASOURCE_DRUID_FILTER_WALL_PREFIX)
    @ConditionalOnProperty(value = SystemPropertiesConstants.Zodiac.SPRING_DATASOURCE_DRUID_FILTER_WALL_ENABLED, havingValue = "true")
    protected com.alibaba.druid.wall.WallFilter wallFilter(com.alibaba.druid.wall.WallConfig wallConfig) {
        //com.alibaba.druid.wall.WallFilter filter = new com.alibaba.druid.wall.WallFilter();
        com.alibaba.druid.wall.WallFilter filter = dataSourceConfigProperties.getDruid().getFilter().getWall();
        filter.setConfig(wallConfig);
        return filter;
    }

    @Bean
    @ConditionalOnMissingBean
    protected org.zodiac.datasource.jdbc.druid.DruidSqlLogInterceptor druidSqlLogInterceptor() {
        return new org.zodiac.datasource.jdbc.druid.DruidSqlLogInterceptor(dataSourceConfigProperties.getDruid().isSqlLog(), dataSourceConfigProperties.getDruid().getSqlLogExcluded());
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy