当前位置: 首页>>代码示例>>Java>>正文


Java DruidDataSourceFactory类代码示例

本文整理汇总了Java中com.alibaba.druid.pool.DruidDataSourceFactory的典型用法代码示例。如果您正苦于以下问题:Java DruidDataSourceFactory类的具体用法?Java DruidDataSourceFactory怎么用?Java DruidDataSourceFactory使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


DruidDataSourceFactory类属于com.alibaba.druid.pool包,在下文中一共展示了DruidDataSourceFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: dataSource

import com.alibaba.druid.pool.DruidDataSourceFactory; //导入依赖的package包/类
private DataSource dataSource() {
    Map<String,Object> properties=new HashMap<>();
    properties.put(DruidDataSourceFactory.PROP_DRIVERCLASSNAME,env.getProperty("spring.datasource.driverClassName"));
    properties.put(DruidDataSourceFactory.PROP_URL,env.getProperty("spring.datasource.url"));
    properties.put(DruidDataSourceFactory.PROP_USERNAME,env.getProperty("spring.datasource.username"));
    properties.put(DruidDataSourceFactory.PROP_PASSWORD,env.getProperty("spring.datasource.password"));
    //添加统计、SQL注入、日志过滤器
    properties.put(DruidDataSourceFactory.PROP_FILTERS,env.getProperty("druid.propFilters"));
    //sql合并,慢查询定义为5s
    properties.put(DruidDataSourceFactory.PROP_CONNECTIONPROPERTIES,env.getProperty("druid.propConnectionProperties"));
    try {
        return DruidDataSourceFactory.createDataSource(properties);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}
 
开发者ID:myopenresources,项目名称:cc-s,代码行数:18,代码来源:MyBatisConfig.java

示例2: definitionDataSource

import com.alibaba.druid.pool.DruidDataSourceFactory; //导入依赖的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;
}
 
开发者ID:justice-code,项目名称:QiuQiu,代码行数:17,代码来源:ApplicationStart.java

示例3: druidDataSource

import com.alibaba.druid.pool.DruidDataSourceFactory; //导入依赖的package包/类
/**
 * druid数据源
 * @return
 */
@Bean
@ConfigurationProperties(prefix = DB_PREFIX)
public DataSource druidDataSource() {

    Properties dbProperties = new Properties();
    Map<String, Object> map = new HashMap<>();
    for (Iterator<PropertySource<?>> it = ((AbstractEnvironment) environment).getPropertySources().iterator(); it.hasNext();) {
        PropertySource<?> propertySource = it.next();
        getPropertiesFromSource(propertySource, map);
    }
    dbProperties.putAll(map);

    DruidDataSource dds = null;
    try {
        dds = (DruidDataSource) DruidDataSourceFactory.createDataSource(dbProperties);
        if (null != dds) {
            dds.init();
        }
    } catch (Exception e) {
        throw new RuntimeException("load datasource error, dbProperties is :" + dbProperties, e);
    }
    return dds;
}
 
开发者ID:qjx378,项目名称:wenku,代码行数:28,代码来源:DruidConfiguration.java

示例4: afterPropertiesSet

import com.alibaba.druid.pool.DruidDataSourceFactory; //导入依赖的package包/类
@Override
public void afterPropertiesSet() {
	if (dataSourceName == null) {
		dataSourceName = Constants.CONF_DATASOURCE_ITEM;
	}
	String path = Config.getContext().getString(dataSourceName);
	try {
		Properties ps = InitTool.loadFile(path);
		DataSource ds = DruidDataSourceFactory.createDataSource(ps);
		if (ps.containsKey("name")) {
			((DruidDataSource) ds).setName(ps.getProperty("name"));
		} else {
			String url = ((DruidDataSource) ds).getRawJdbcUrl();
			String ip_port = url.split("/")[2].replaceAll(":", "_");
			((DruidDataSource) ds).setName(ip_port);
		}
		setTargetDataSource(ds);
	} catch (Exception e) {
		Validate.isTrue(false, "DataSource Init Error");
	}
	super.afterPropertiesSet();
}
 
开发者ID:peiliping,项目名称:excalibur,代码行数:23,代码来源:DataSourceProxy.java

示例5: handleEvent

import com.alibaba.druid.pool.DruidDataSourceFactory; //导入依赖的package包/类
@Subscribe
public void handleEvent(Map<String, ConfigItem> config) {
	if (!config.containsKey(this.davinciCode))
		return;
	ConfigItem ci = config.get(this.davinciCode);
	if (this.configItem != null && this.configItem.getVersion() >= ci.getVersion())
		return;

	try {
		setTargetDataSource(DruidDataSourceFactory.createDataSource(buildProperties(ci)));
		super.afterPropertiesSet();
		getTargetDataSource().getConnection().isValid(1000);
		this.configItem = ci;
	} catch (Exception e) {
		LOG.error("DataSourceUnit Handle Event Error : ", e);
		Validate.isTrue(false, e.getMessage());
	}
}
 
开发者ID:peiliping,项目名称:excalibur,代码行数:19,代码来源:DataSourceUnit.java

示例6: getDataSource

import com.alibaba.druid.pool.DruidDataSourceFactory; //导入依赖的package包/类
public static DataSource getDataSource() {
	if (dataSource == null) {
		try {
			dataSource = DruidDataSourceFactory.createDataSource(loadPropertyFile(configFile));
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	return dataSource;
}
 
开发者ID:liufeng0103,项目名称:bnade-server,代码行数:11,代码来源:DBUtils.java

示例7: test1DataSource

import com.alibaba.druid.pool.DruidDataSourceFactory; //导入依赖的package包/类
@Bean
public DataSource test1DataSource() throws Exception {
    Properties props = new Properties();
    props.put("driverClassName", environment.getProperty("dbpool.database1.driver-class-name"));
    props.put("url", environment.getProperty("dbpool.database1.url"));
    props.put("username", environment.getProperty("dbpool.database1.username"));
    props.put("password", environment.getProperty("dbpool.database1.password"));
    return DruidDataSourceFactory.createDataSource(props);
}
 
开发者ID:helloworldtang,项目名称:springboot-multi-datasource,代码行数:10,代码来源:DataSourceConfig_2.java

示例8: test2DataSource

import com.alibaba.druid.pool.DruidDataSourceFactory; //导入依赖的package包/类
@Bean
@Primary
public DataSource test2DataSource() throws Exception {
    Properties props = new Properties();
    props.put("driverClassName", environment.getProperty("dbpool.database2.driver-class-name"));
    props.put("url", environment.getProperty("dbpool.database2.url"));
    props.put("username", environment.getProperty("dbpool.database2.username"));
    props.put("password", environment.getProperty("dbpool.database2.password"));
    return DruidDataSourceFactory.createDataSource(props);
}
 
开发者ID:helloworldtang,项目名称:springboot-multi-datasource,代码行数:11,代码来源:DataSourceConfig_2.java

示例9: test1DataSource

import com.alibaba.druid.pool.DruidDataSourceFactory; //导入依赖的package包/类
/**
 * 创建数据源(数据源的名称:方法名可以取为XXXDataSource(),XXX为数据库名称,该名称也就是数据源的名称)
 */
@Bean
public DataSource test1DataSource() throws Exception {
    Properties props = new Properties();
    props.put("driverClassName", environment.getProperty("test1-datasource.driverClassName"));
    props.put("url", environment.getProperty("test1-datasource.url"));
    props.put("username", environment.getProperty("test1-datasource.username"));
    props.put("password", environment.getProperty("test1-datasource.password"));
    return DruidDataSourceFactory.createDataSource(props);
}
 
开发者ID:heikehuan,项目名称:springboot-multiple-dataSources,代码行数:13,代码来源:MyBatisConfig.java

示例10: test2DataSource

import com.alibaba.druid.pool.DruidDataSourceFactory; //导入依赖的package包/类
@Bean
public DataSource test2DataSource() throws Exception {
    Properties props = new Properties();
    props.put("driverClassName", environment.getProperty("test2-datasource.driverClassName"));
    props.put("url", environment.getProperty("test2-datasource.url"));
    props.put("username", environment.getProperty("test2-datasource.username"));
    props.put("password", environment.getProperty("test2-datasource.password"));
    return DruidDataSourceFactory.createDataSource(props);
}
 
开发者ID:heikehuan,项目名称:springboot-multiple-dataSources,代码行数:10,代码来源:MyBatisConfig.java

示例11: JdbcOperatorUnit

import com.alibaba.druid.pool.DruidDataSourceFactory; //导入依赖的package包/类
public JdbcOperatorUnit() {
    //只构建一次数据源
    if(dataSource==null) {
        try {
            String druidpath = TFile.getSystemPath("/classes/database.properties");
            Properties druidProperites = TProperties.getProperties(new File(druidpath));
            dataSource = (DruidDataSource)DruidDataSourceFactory.createDataSource(druidProperites);
            dataSource.init();
            Logger.info("Database connection pool init finished");
        } catch (Exception e) {
            Logger.error(e);
        }
    }
}
 
开发者ID:helyho,项目名称:Voovan,代码行数:15,代码来源:JdbcOperatorUnit.java

示例12: init

import com.alibaba.druid.pool.DruidDataSourceFactory; //导入依赖的package包/类
/**
 * 连接初始化
 * 
 * @throws java.lang.Exception 
 */
public synchronized static void init() throws Exception {
    /* 导入配置文件形成的mapMAP */
    config = loadProerties();
    for (Map.Entry<String, Map<String, String>> row : config.entrySet()) {
        _DATASOURCEMAP.put(row.getKey(),
                DruidDataSourceFactory.createDataSource(config.get(row.getKey())));
    }
     log.info("线程池初始化完毕..");
}
 
开发者ID:taojiaenx,项目名称:taojiane_push,代码行数:15,代码来源:DbHelper.java

示例13: configure

import com.alibaba.druid.pool.DruidDataSourceFactory; //导入依赖的package包/类
@SuppressWarnings("rawtypes")
@Override
public void configure(Map configurationValues) {
	logger.info("DruidDataSource init:: "+configurationValues);
    try {
        DruidDataSourceFactory.config(dataSource, configurationValues);
    } catch (SQLException e) {
        throw new IllegalArgumentException("config error", e);
    }
}
 
开发者ID:guocw998,项目名称:SHD201407-app,代码行数:11,代码来源:DruidConnectionProvider.java

示例14: getDataSource

import com.alibaba.druid.pool.DruidDataSourceFactory; //导入依赖的package包/类
public static DataSource getDataSource() {
	if(source == null){
		Properties properties = new Properties();
		try {
			InputStream in = DbPoolConnection.class.getClassLoader().getResourceAsStream(FILE_NAME);
			properties.load(in);
			source = (DruidDataSource) DruidDataSourceFactory.createDataSource(properties);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	return source;
	
}
 
开发者ID:huajun2013,项目名称:ablaze,代码行数:15,代码来源:DbPoolConnection.java

示例15: setUp

import com.alibaba.druid.pool.DruidDataSourceFactory; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
    File configFile = new File("application.properties");
    FileInputStream fis = new FileInputStream(configFile);
    BufferedInputStream bis = new BufferedInputStream(fis);
    Properties prop = new Properties();
    prop.load(bis);
    bis.close();
    dataSource = DruidDataSourceFactory.createDataSource(prop);
}
 
开发者ID:terrason,项目名称:lib-mptta,代码行数:11,代码来源:DragAndDropTest.java


注:本文中的com.alibaba.druid.pool.DruidDataSourceFactory类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。