本文整理匯總了Java中com.alibaba.druid.pool.DruidDataSource.setProxyFilters方法的典型用法代碼示例。如果您正苦於以下問題:Java DruidDataSource.setProxyFilters方法的具體用法?Java DruidDataSource.setProxyFilters怎麽用?Java DruidDataSource.setProxyFilters使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.alibaba.druid.pool.DruidDataSource
的用法示例。
在下文中一共展示了DruidDataSource.setProxyFilters方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: definitionDataSource
import com.alibaba.druid.pool.DruidDataSource; //導入方法依賴的package包/類
@Bean
public DataSource definitionDataSource() throws Exception {
StatFilter statFilter = new StatFilter();
Properties config = new Properties();
config.setProperty("url", dataSourceProperties.getUrl());
config.setProperty("username", dataSourceProperties.getUsername());
config.setProperty("password", dataSourceProperties.getPassword());
config.setProperty("driverClassName", dataSourceProperties.getDriverClassName());
config.setProperty("filters", "slf4j");
DruidDataSource dataSource = (DruidDataSource) DruidDataSourceFactory.createDataSource(config);
dataSource.setProxyFilters(Collections.singletonList(statFilter));
return dataSource;
}
示例2: buildDruidDataSource
import com.alibaba.druid.pool.DruidDataSource; //導入方法依賴的package包/類
/**
* 創建數據源,有前綴
*
* @param dataSourceMap
* @param prefix
* @return
* @throws SQLException
*/
private DruidDataSource buildDruidDataSource(Map<String, Object> dataSourceMap, String prefix) throws SQLException {
DruidDataSource dataSource = new DruidDataSource();
dataSource.setName(MapUtils.getString(dataSourceMap, prefix + "name"));
dataSource.setDriverClassName(MapUtils.getString(dataSourceMap, prefix + "driverClass"));
dataSource.setUrl(MapUtils.getString(dataSourceMap, prefix + "url"));
dataSource.setUsername(MapUtils.getString(dataSourceMap, prefix + "username"));
dataSource.setPassword(MapUtils.getString(dataSourceMap, prefix + "password"));
// 配置過濾器
WallFilter wallFilter = new WallFilter();
StatFilter statFilter = new StatFilter();
statFilter.setSlowSqlMillis(5000);
statFilter.setLogSlowSql(true);
statFilter.setMergeSql(true);
Slf4jLogFilter slf4jLogFilter = new Slf4jLogFilter();
slf4jLogFilter.setDataSourceLogEnabled(false);
slf4jLogFilter.setConnectionLogEnabled(false);
slf4jLogFilter.setConnectionLogErrorEnabled(true);
slf4jLogFilter.setResultSetLogEnabled(false);
slf4jLogFilter.setResultSetLogErrorEnabled(true);
slf4jLogFilter.setStatementLogEnabled(false);
slf4jLogFilter.setStatementExecutableSqlLogEnable(true);
slf4jLogFilter.setStatementSqlFormatOption(new SQLUtils.FormatOption(false, false));
List filterList = new ArrayList();
filterList.add(wallFilter);
filterList.add(statFilter);
filterList.add(slf4jLogFilter);
dataSource.setProxyFilters(filterList);
return dataSource;
}
示例3: dataSource
import com.alibaba.druid.pool.DruidDataSource; //導入方法依賴的package包/類
@Bean
@Primary
public DataSource dataSource(){
DruidDataSource datasource = new DruidDataSource();
datasource.setUrl(this.dbUrl);
datasource.setUsername(username);
datasource.setPassword(password);
datasource.setDriverClassName(driverClassName);
//configuration
if(initialSize != null) {
datasource.setInitialSize(initialSize);
}
if(minIdle != null) {
datasource.setMinIdle(minIdle);
}
if(maxActive != null) {
datasource.setMaxActive(maxActive);
}
if(maxWait != null) {
datasource.setMaxWait(maxWait);
}
if(timeBetweenEvictionRunsMillis != null) {
datasource.setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis);
}
if(minEvictableIdleTimeMillis != null) {
datasource.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis);
}
if(validationQuery!=null) {
datasource.setValidationQuery(validationQuery);
}
if(testWhileIdle != null) {
datasource.setTestWhileIdle(testWhileIdle);
}
if(testOnBorrow != null) {
datasource.setTestOnBorrow(testOnBorrow);
}
if(testOnReturn != null) {
datasource.setTestOnReturn(testOnReturn);
}
if(poolPreparedStatements != null) {
datasource.setPoolPreparedStatements(poolPreparedStatements);
}
if(maxPoolPreparedStatementPerConnectionSize != null) {
datasource.setMaxPoolPreparedStatementPerConnectionSize(maxPoolPreparedStatementPerConnectionSize);
}
if(connectionProperties != null) {
datasource.setConnectionProperties(connectionProperties);
}
List<Filter> filters = new ArrayList<>();
filters.add(statFilter());
filters.add(wallFilter());
datasource.setProxyFilters(filters);
return datasource;
}