Spring Boot 2.x + Hibernate 5.x + Multiple Datasource - Init Project
Before start
The new project is required to use new platform, which we will abandon the historical architecture. It is a challenge and need to make a courage to move a comfortable bed to a rough floor.
The previous platform is built by Spring framework 4.x + Hibernate 3.x. All modules are intergrated in one Java project. Everything runs smoothly and easy to add new moudle in it (despite the transaction has a little bit problem, occasionally cannot rollback by transaction manager )
Why we plan to move spring boot, should be another topic, but before we really copy and paste business code, the architecture should satisfy basic requirement: database CRUD.
The first topic is, connect to multiple brand database and execute CRUD
Init the project
By the IntelJ help, to init a new project is a unbelieveably simple task, here is the step:
-
Use Spring Initialzr
-
Input the aritfact etc.
Ingore this part, please follow guide -
Choose the dependencies
JPA is necessary, other brand database should follow your need.
Please beware, there is no Oracle driver because license prohibit
-
Finish the project init
Complete the maven dependencies
Base on project requirement to complete the dependencies.
One thing need to reminder
if you connect to Oracle database, the OJDBC driver should be new verion
ojdbc version should upgrade to 11g or above, because there are some bugs between java and JPA, hibernate version
There is a download link:
https://www.oracle.com/technetwork/documentation/jdbc-112010-090769.html
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc16</artifactId>
<version>11.2.0.4</version>
</dependency>