hikari数据源配置类_如何在Spring @Configuration类中使用HikariCP配置数据源?

I'm trying to configure HikariCP datasource in Spring @Configuration class[Database being oracle]. But it's not working.

I searched in the internet and found that HikariCP datasource needs to be configured with constructor. I have tried this [the way it's mentioned in their github webpage], but it still not working. Please help me in solving this problem.

private HikariDataSource dataSource() {

final HikariDataSource ds = new HikariDataSource();

ds.setMaximumPoolSize(100);

ds.setDataSourceClassName("oracle.jdbc.driver.OracleDriver");

ds.addDataSourceProperty("url", "jdbc:oracle:thin:@localhost:1521:XE");

ds.addDataSourceProperty("user", "username");

ds.addDataSourceProperty("password", "password");

ds.addDataSourceProperty("cachePrepStmts", true);

ds.addDataSourceProperty("prepStmtCacheSize", 250);

ds.addDataSourceProperty("prepStmtCacheSqlLimit", 2048);

ds.addDataSourceProperty("useServerPrepStmts", true);

return ds;

}

解决方案

You can check out our example in the wiki here:

As covered by this article:

EDIT:

The code provided above is incorrect. You are trying to use MySQL DataSource properties for an Oracle DataSource. And now you're mixing up a Driver-based configuration with a DataSource-based one. Simplify it:

Driver:

private HikariDataSource dataSource() {

final HikariDataSource ds = new HikariDataSource();

ds.setMaximumPoolSize(100);

ds.setDriverClassName("oracle.jdbc.driver.OracleDriver");

ds.setJdbcUrl("jdbc:oracle:thin:@localhost:1521:XE"); ;

ds.setUsername("username");

ds.setPassword("password");

return ds;

}

OR DataSource:

private HikariDataSource dataSource() {

final HikariDataSource ds = new HikariDataSource();

ds.setMaximumPoolSize(100);

ds.setDataSourceClassName("oracle.jdbc.pool.OracleDataSource");

ds.addDataSourceProperty("serverName", "yourServer");

ds.addDataSourceProperty("port", "1521");

ds.addDataSourceProperty("databaseName", "XE");

ds.addDataSourceProperty("user", "username");

ds.addDataSourceProperty("password", "password");

return ds;

}

Also, 100 connection is way to big for Oracle unless you are running 20K transactions per-second, 10-20 is more reasonable.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值