Skip to content
Advertisement

How to implement configuration to use oracle/postgreSQL dataSource with spring+mybatis framework?

Background: spring + mybatis + oracle data source

Requirement: support postgreSQL data source exchange with minimum code change

Example:

Current: controllerA -> ServiceA -> daoA -> A.xml (oracle)

Now need: we can configure use oracele/postgreSQL database source

If configure use postgreSQL: controllerA -> ServiceA -> daoA -> A.xml (postgreSQL)

More:

Same controllerA、ServiceA for same business logic

Differenct DaoA、A.xml for oracle and postgreSQL mybatis sql implementation

DaoA is better to be same if it can be.

The data and sql logic is the same for oracle and postgreSQL, just need a congfiguration to change to use oracle/postgreSQL implementation.

How to implement it?

Answer

Solution is on the comments: use databaseIdProvider technique will work

Advertisement