springboot動(dòng)態(tài)切換數(shù)據(jù)源 springboot配置兩個(gè)數(shù)據(jù)源怎么實(shí)現(xiàn)?
springboot配置兩個(gè)數(shù)據(jù)源怎么實(shí)現(xiàn)?配置多個(gè)數(shù)據(jù)源信息,如datasource1、datasource2、datasource3等,定義一個(gè)動(dòng)態(tài)數(shù)據(jù)源類,同時(shí)注入上述數(shù)據(jù)源和相應(yīng)的標(biāo)志。一般用
springboot配置兩個(gè)數(shù)據(jù)源怎么實(shí)現(xiàn)?
配置多個(gè)數(shù)據(jù)源信息,如datasource1、datasource2、datasource3等,定義一個(gè)動(dòng)態(tài)數(shù)據(jù)源類,同時(shí)注入上述數(shù)據(jù)源和相應(yīng)的標(biāo)志。一般用地圖來(lái)區(qū)分。使用動(dòng)態(tài)數(shù)據(jù)源類得到相應(yīng)的數(shù)據(jù)源操作
A.直接配置兩組數(shù)據(jù)源,就像下面最簡(jiǎn)單的@configuration公共類springconfig{@bean public datasource datasource(){return new xxdatasource()}@bean public Counter datasource2(){return new xxdatasource()}}B.在復(fù)合數(shù)據(jù)源只讀分離庫(kù)中實(shí)現(xiàn)complexds