I'm trying to configure a Spring Boot application with two datasources using same repositories and models, but when spring boot start says that repositories are already defined and can't create another on the bean container. That's true I mean.. I accept the error..but I would like to know if there is any way to do this. Below an idea of what I would like to do
- Datasoruce(H2) for local deploy ----> com.myapp.repositories
- Datasource(SQLServer) for remote deploy ----> com.myapp.repositories
My problem is that even if I'm doing the deploy on my local machine ..I need my remote datasource to do some operation.. In other world both local and remote Datasource connections should be up during local deploy.
I found actually three solution:
- The first is @Profile the @Configuration one for "prod" one for "dev"..but in my case don't work.
- Second one is to put different repositories package for each configuration. This work but I need to move all repositories when I go live.
- Third solution is to do always two configuration and don't specify the basePackages on the remote Datasource. This work but I need to change this parameter when I go live.
Is there any other solution to do this? Thank you for help.