新闻资讯

新闻资讯 媒体报道

Java DruidDataSourceFactory类代码示例

编辑:016     时间:2021-12-15

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

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

示例1: dataSource

 点赞 3 
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

 点赞 3 
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

 点赞 3 
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

 点赞 3 
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

 点赞 3 
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

 点赞 2 
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

 点赞 2 
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

 点赞 2 
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

 点赞 2 
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

 点赞 2 
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

 点赞 2 
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

 点赞 2 
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

 点赞 2 
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

 点赞 2 
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

 点赞 2 
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


示例16: DruidDataSourceProvider

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


示例17: createDataSource

 点赞 2 
import com.alibaba.druid.pool.DruidDataSourceFactory; //导入依赖的package包/类 public static DruidDataSource createDataSource(String dataSourceName, Map<?, ?> dataSourceConfig) throws Exception {
    DruidDataSource dataSource = new DruidDataSource(); DruidDataSourceFactory.config(dataSource, dataSourceConfig);
    dataSourcesPool.put(dataSourceName, dataSource); return dataSource;
}
开发者ID:MinsxCloud,项目名称:minsx-java-example,代码行数:7,代码来源:DataSourceFactory.java


示例18: DruidConnectionPool

 点赞 2 
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


示例19: getConnection

 点赞 2 
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


示例20: definitionDataSource

 点赞 2 
import com.alibaba.druid.pool.DruidDataSourceFactory; //导入依赖的package包/类 @Bean public DataSource definitionDataSource() throws Exception { return DruidDataSourceFactory.createDataSource(config.genProperties());
}
开发者ID:Justice-love,项目名称:stockAnalysis,代码行数:5,代码来源:ApplicationStart.java
郑重声明:本文版权归原作者所有,转载文章仅为传播更多信息之目的,如作者信息标记有误,请第一时间联系我们修改或删除,多谢。

回复列表

相关推荐