spring多資料來源配置實現方法例項分析

2022-10-03 17:54:11 字數 671 閱讀 7363

在網上找到的配置多資料來源的方法。

1.擴充套件org.springframework.jdbc.datasource.lookup.abstractroutingdatasource類

實現**

import org.springframework.jdbc.datasource.lookup.abstractroutingdatasource;

public class dynamicdatasource extends abstractroutingdatasource

}2.實現乙個執行緒安全的dbcontextholder類。

public class dbcontextholder

/*** 取得dbtype型別

* @return

*/public static strin getdbtype()

public static void cleardbtype()

}3.修改spring的配置檔案。

j**a.lang.string">

" value="$"/>

程式設計客棧"password" value="$"/>

4.切換資料來源方法。

在serverice方法之前呼叫

dbcontextholippmhder.setdbtype("2");表示使用第二個資料來源。

spring多資料來源配置

前段時間由於公司專案需求,需要多資料來源的支援,苦b折騰了兩天程式猿,話不多說,直接擼碼。classpath jdbc.properties select 1 true select 1 true org.hibernate.dialect.mysqldialect false update tru...

spring 多資料來源配置

以下是我的xml配置,在配置的過程中涉及到不同的包分配不同的資料來源,在這裡用逗號分割就好 當然萬用字元能結局的那是最好了.xmlns xsi xmlns aop xmlns tx xmlns task xmlns context xmlns rabbit xsi schemalocation sp...

spring 多資料來源配置方式

核心配置檔案 com.util.dialectforinkfish true none com.common.model 1.基於註解的配置方式 可以在類或方法上註解 1 xml 2 class retention retentionpolicy.runtime target public inte...