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


Java DruidDataSourceFactory.createDataSource方法代码示例

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


在下文中一共展示了DruidDataSourceFactory.createDataSource方法的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: 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

示例6: 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

示例7: 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

示例8: 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

示例9: 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

示例10: 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

示例11: 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

示例12: 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

示例13: DruidDataSourceProvider

import com.alibaba.druid.pool.DruidDataSourceFactory; //导入方法依赖的package包/类
public DruidDataSourceProvider(Properties properties) throws Exception {
    ds = DruidDataSourceFactory.createDataSource(properties);
}
 
开发者ID:BriData,项目名称:DBus,代码行数:4,代码来源:DruidDataSourceProvider.java

示例14: DruidConnectionPool

import com.alibaba.druid.pool.DruidDataSourceFactory; //导入方法依赖的package包/类
public DruidConnectionPool(String configFile) throws Exception {
    InputStream in = FileLoaderUtil.findInputStreamByFileName(configFile);
    Properties props = new Properties();
    props.load(in);
    ds = DruidDataSourceFactory.createDataSource(props);
}
 
开发者ID:beimi,项目名称:ServerCore,代码行数:7,代码来源:DruidConnectionPool.java

示例15: getConnection

import com.alibaba.druid.pool.DruidDataSourceFactory; //导入方法依赖的package包/类
public static Connection getConnection(String url,
                                       String userName, String password, EDatabaseType databaseType) throws Exception {

    String driverClassName = "";
    if (EDatabaseType.MYSQL.equals(databaseType)) {
        driverClassName = "com.mysql.jdbc.Driver";
    }

    if (EDatabaseType.ORACLE.equals(databaseType)) {
        driverClassName = "oracle.jdbc.driver.OracleDriver";
    }


    Map<String, String> config = new HashMap<>();
    config.put("url", url);
    config.put("driverClassName", driverClassName);
    config.put("username", userName);
    config.put("password", password);


    DataSource dataSource = DruidDataSourceFactory.createDataSource(config);

    return dataSource.getConnection();

}
 
开发者ID:wangdao,项目名称:x-worker,代码行数:26,代码来源:DatabaseUtil.java


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