本文整理汇总了Java中com.alibaba.druid.pool.DruidDataSource.init方法的典型用法代码示例。如果您正苦于以下问题:Java DruidDataSource.init方法的具体用法?Java DruidDataSource.init怎么用?Java DruidDataSource.init使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.alibaba.druid.pool.DruidDataSource
的用法示例。
在下文中一共展示了DruidDataSource.init方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: mysqlDataSource
import com.alibaba.druid.pool.DruidDataSource; //导入方法依赖的package包/类
public DataSource mysqlDataSource() throws Exception{
DruidDataSource druidDataSource = new DruidDataSource();
druidDataSource.setUrl(this.url);
druidDataSource.setUsername(this.username);
druidDataSource.setPassword(this.password);
druidDataSource.setDriverClassName(this.driverClassName);
druidDataSource.setInitialSize(this.initialSize);
druidDataSource.setMaxActive(this.maxActive);
druidDataSource.setMinIdle(this.minIdle);
druidDataSource.setMaxWait(this.maxWait);
druidDataSource.setTimeBetweenEvictionRunsMillis(this.timeBetweenEvictionRunsMillis);
druidDataSource.setMinEvictableIdleTimeMillis(this.minEvictableIdleTimeMillis);
druidDataSource.setValidationQuery(this.validationQuery);
druidDataSource.setTestWhileIdle(this.testWhileIdle);
druidDataSource.setTestOnBorrow(this.testOnBorrow);
druidDataSource.setTestOnReturn(this.testOnReturn);
druidDataSource.setPoolPreparedStatements(this.poolPreparedStatements);
druidDataSource.setMaxPoolPreparedStatementPerConnectionSize(this.maxPoolPreparedStatementPerConnectionSize);
druidDataSource.setFilters(this.filters);
try {
druidDataSource.setFilters("wall,stat");
druidDataSource.setUseGlobalDataSourceStat(true);
druidDataSource.init();
} catch (Exception e) {
throw new RuntimeException("load datasource error, dbProperties is :", e);
}
return druidDataSource;
}
示例2: init
import com.alibaba.druid.pool.DruidDataSource; //导入方法依赖的package包/类
public void init() throws Exception{
System.out.println("**************init");
MicroMetaDao dao=MicroMetaDao.getInstance();
String sql="select * from nh_micro_dbconf";
List<Map<String,Object>> infoList=dao.queryObjJoinByCondition(sql);
for(Map<String,Object> row:infoList){
String metaKey=(String) row.get("meta_key");
String dataSourceClassName=(String) row.get("datasource_classname");
String dbUser=(String) row.get("db_user");
String dbPassWord=(String) row.get("db_password");
if(dbPassWord.startsWith("nhjm-")){
String temp=dbPassWord.substring(5);
dbPassWord=DESUtil.decrypt(temp);
}
String dbUrl=(String) row.get("db_url");
DruidDataSource ds=new DruidDataSource();
ds.setUsername(dbUser);
ds.setPassword(dbPassWord);
ds.setUrl(dbUrl);
ds.setFilters("stat");
ds.setMaxActive(10);
ds.setInitialSize(1);
ds.setMaxWait(60000);
ds.setMinIdle(1);
ds.setTimeBetweenEvictionRunsMillis(60000);
ds.setMinEvictableIdleTimeMillis(60000);
ds.setValidationQuery("SELECT 'x'");
ds.setTestWhileIdle(true);
ds.setTestOnBorrow(false);
ds.setTestOnReturn(false);
ds.setPoolPreparedStatements(true);
ds.setMaxPoolPreparedStatementPerConnectionSize(10);
ds.setDriverClassName(dataSourceClassName);
ds.init();
JdbcTemplate jdbcTemplate=new JdbcTemplate();
jdbcTemplate.setDataSource(ds);
MicroDbHolder.getDbHolder().put(metaKey, jdbcTemplate);
}
}
示例3: init
import com.alibaba.druid.pool.DruidDataSource; //导入方法依赖的package包/类
public void init() throws SQLException {
logger.debug("初始化 DynamicDataSource {}...",this.dataSourceName);
this.masterDataSource.init();
Iterator<DruidDataSource> it = this.slaveDataSources.values().iterator();
while (it.hasNext()) {
DruidDataSource druidDataSource = (DruidDataSource) it.next();
try {
druidDataSource.init();
} catch (SQLException e) {
logger.warn("从库{}初始化失败", druidDataSource.getName());
}
}
}