multi-mybatis-demo icon indicating copy to clipboard operation
multi-mybatis-demo copied to clipboard

Can I implement it as one-default datasource and other is optional?

Open xenogew opened this issue 3 years ago • 1 comments

I saw your example and try on my codes, but I found some issues.

  1. I'm implementing Spring Batch which use database to save its job/step/etc of running.
  2. 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.

xenogew avatar Aug 10 '21 08:08 xenogew

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?

Verdoso avatar Aug 12 '21 09:08 Verdoso