本文整理汇总了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;
}
示例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;
}
示例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;
}
示例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();
}
示例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;
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
}
}
示例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;
}
示例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);
}
示例13: DruidDataSourceProvider
import com.alibaba.druid.pool.DruidDataSourceFactory; //导入方法依赖的package包/类
public DruidDataSourceProvider(Properties properties) throws Exception {
ds = DruidDataSourceFactory.createDataSource(properties);
}
示例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);
}
示例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();
}