Spring: Initialize multiple connection pools at st

2019-06-05 20:20发布

问题:

I want to initialize multiple connection pools at context startup by reading connection parameters from a database table. Basically I want to address following two things

  1. Read connection properties from database not the properties file.

  2. Their are multiple connection pool(rows in db) details.

So my question is How can I iterate over list of rows returned by database in spring-context file and create multiple data-source objects and store them (Lets say in a map) with a unique key?

Databse table structure are somewhat like following:

+--------------+----------------+---------------+
| DBSERVERNAME | DBDRIVERCLASS  | DBMINPOOLSIZE |
+--------------+----------------+---------------+
| Server1      | Mysql-Driver   |            10 |
| Server2      | Oracle-Driver  |            20 |
| Server3      | DB2-Driver     |            10 |
+--------------+----------------+---------------+

Let me know if more details are needed. Thanks.