template和資料來源配置

2021-10-23 17:28:20 字數 2056 閱讀 1173

一般使用模板(template)來運算元據庫的話,都需要給template設定乙個連線工廠或者資料來源,告訴這個模板從什麼地方獲取連線,比如像redistemplate、hibernatetemplate(hibernate3)、jdbctemplate

@bean

public redistemplate

redistemplate

(redisconnectionfactory cf)

// hibernatetemplate的建構函式

public

hibernatetemplate

(sessionfactory sessionfactory)

// 同時session工廠bean的配置如下

@bean

public localsessionfactorybean sessionfactory

(datasource datasource));

properties props =

newproperties()

; props.

setproperty

("dialect"

,"org.hibernate.dialect.h2dialcet");

sfb.

sethibernateproperties

(props)

;return sfb;

}// 使用localsessionfactorybean來構建hibernatetemplate

遇到乙個問題,就是mybatis的配置不生效,經過分析,發現之前的**中配置過sqlsessionfactory,但是沒有給sqlsessionfactory配置configuration,所以不生效。最後自己寫了個資料來源配置。這種寫法參考於

//@configuration

@configurationproperties

(prefix =

"my.datasource"

)(basepackages =

, sqlsessionfactoryref =

"mysqlsessionfactory"

)@component

@data

public

class

datasourceconfig

")private string jdbcurl;//

@value

("$"

)private string username;//

@value

("$"

)private string password;//

@value

("$"

)private string driverclassname;//

@value

("$"

)private

int maximumpoolsize;//

@value

("$"

)private

int minimumidle;

@bean

(name =

"mydatasource"

)public datasource mydatasource()

@bean

(name =

"mytransactionmanager"

)public datasourcetransactionmanager clustertransactionmanager()

@bean

(name =

"mysqlsessionfactory"

)public sqlsessionfactory clustersqlsessionfactory

(@qualifier

("mydatasource"

) datasource mydatasource)

throws exception

}

WPF 的 資料來源屬性 和 資料來源

一 資料來源 資料物件 屬性 path 或 path的值 path vm.property或m.property 通常具有通知功能 特例除外 二 path不能孤立而存在,它一定具有所歸屬的資料來源,一定要找到path 確切的說 是它的值 所歸屬的資料來源,說明如下 資料來源 資料物件 1 指定控制項...

資料來源配置

1 建立資料庫student。2 新建表puser。3 設定資料來源,選擇windows選單 控制面板 管理工具 資料來源 odbc 彈出 odbc資料來源管理器 在彈出 odbc資料來源管理器 對話方塊中,選擇 系統dns 選項卡,單擊 新增 按鈕。在彈出的 建立新資料來源 對話方塊中,選擇 mi...

配置資料來源

jdbc.properties檔案 dzswb2b.druid.alias dbccfw dzswb2b.druid.driver url jdbc oracle thin 10.1.94.252 1521 dzsw dzswb2b.druid.username ccfw dzswb2b.druid...