multi-mybatis-demo
multi-mybatis-demo copied to clipboard
Can I implement it as one-default datasource and other is optional?
I saw your example and try on my codes, but I found some issues.
- I'm implementing Spring Batch which use database to save its job/step/etc of running.
- Your code is differentiate base on Mapper it binding with, how in the case of do everything with default-datasource, but only expected Mapper do with optional datasource?
All answers or solutions are welcome, Thanks in advance.
Hi there,
Supposedly, that's what the @Primary
annotation is for. When Spring has to choose a default datasource for something, it will use the one that is marked with @Primary
.
It can be problematic if you want to mix two libraries that depend on different "default datasources" but then you would probably have to configure something manually instead of relying on default/auto configurations.
Have you tried specifying the one you want Spring Bath to use with @Primary
? Is it not working?