How to configure datasource with HikariCP in Spring @Configuration class?

前端 未结 2 1803
隐瞒了意图╮
隐瞒了意图╮ 2020-12-29 08:52

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

2条回答
  •  被撕碎了的回忆
    2020-12-29 09:16

    Something like the following should fit your needs:

    @Bean
    public DataSource dataSource() {
         HikariConfig config = new HikariConfig();
         config.setMaximumPoolSize(100);
         config.setDataSourceClassName("oracle.jdbc.pool.OracleDataSource");
         config.addDataSourceProperty("serverName", "localhost");
         config.addDataSourceProperty("port", "1521");
         config.addDataSourceProperty("databaseName", "XE");
         config.addDataSourceProperty("user", "yourUser");
         config.addDataSourceProperty("password", "yourPassword");
    
         return new HikariDataSource(config);
    }
    

提交回复
热议问题