@configuration
@enabletransactionmanagement
public class druiddatesourceconfig ")
private string driverclass;
@value("$")
private string jdbcurl;
@value("$")
private string user;
@value("$")
private string password;
@value("$")
private int initialsize;
@value("$")
private int minidle;
@value("$")
private int maxactive;
@value("$")
private long maxwait;
@value("$")
private long timebetweenevictionrunsmillis;
@value("$")
private long minevictableidletimemillis;
@value("$")
private string validationquery;
@value("$")
private boolean testwhileidle;
@value("$")
private boolean testonborrow;
@value("$")
private boolean testonreturn;
@value("$")
//開啟pscache,並且指定每個連線上pscache的大小
private boolean poolpreparedstatements;
@value("$")
private int maxpoolpreparedstatementperconnectionsize;
@value("$")
//配置監控統計攔截的filters,去掉後監控介面sql無法統計,'wall'用於防火牆
//@value("$") 關閉防火牆
private string filters;
@value("$")
//通過connectproperties屬性來開啟mergesql功能;慢sql記錄
private string connectionproperties;
@value("$")
//合併多個druiddatasource的監控資料
private boolean useglobaldatasourcestat;
@bean(initmethod = "init",destroymethod = "close")
public datasource datasource() catch (sqlexception e)
datasource.setconnectionproperties(connectionproperties);
return datasource;
// druiddatasource druiddatasource = new druiddatasource();
// druiddatasource.seturl(jdbcurl);
// druiddatasource.setusername(user);
// druiddatasource.setpassword(password);
//// druiddatasource.setinitialsize(initialsize);
// druiddatasource.setminidle(minidle);
// druiddatasource.setmaxactive(maxactive);
//// //配置獲取連線等待超時的時間
// druiddatasource.setmaxwait(maxwait);
//// //配置間隔多久才進行一次檢測,檢測需要關閉的空閒連線,單位是毫秒
// druiddatasource.settimebetweenevictionrunsmillis(timebetweenevictionrunsmillis);
//// //配置乙個連線在池中最小生存的時間,單位是毫秒
// druiddatasource.setminevictableidletimemillis(minevictableidletimemillis);
//// druiddatasource.setvalidationquery(validationquery);
//// druiddatasource.settestwhileidle(testwhileidle);
// druiddatasource.settestonborrow(testonborrow);
// druiddatasource.settestonreturn(testonreturn);
//// druiddatasource.setpoolpreparedstatements(poolpreparedstatements);
// druiddatasource.setmaxpoolpreparedstatementperconnectionsize(maxpoolpreparedstatementperconnectionsize);
//// return druiddatasource;
}@bean(value = "sqlsessiontemplate")
public sqlsessiontemplate sqlsessiontemplate(@qualifier("sqlsessionfactory") sqlsessionfactory sqlsessionfactory)
@autowired
@qualifier("masterpageinterceptor")
pageinterceptor pageinterceptor;
@bean(value = "sqlsessionfactory")
public mybatissqlsessionfactorybean sqlsessionfactory(@qualifier("datasource") datasource datasource) throws exception );
return sqlsessionfactorybean;
}resourcepatternresolver resourceresolver = new pathmatchingresourcepatternresolver();
listresources = new arraylist();
try catch (ioexception e) }}
return resources.toarray(new resource[resources.size()]);
}@bean(value = "transactiontemplate")
public transactiontemplate transactiontemplate(@qualifier("transactionmanager") platformtransactionmanager transactionmanager)
@bean(value = "transactionmanager")
public platformtransactionmanager transactionmanager(@qualifier("datasource") datasource datasource)
}
注意點:如果需要一次執行多條sql語句(&allowmultiqueries=true)需要關閉防火牆安全配置否則會有異常
@bean(name = "wallconfig")
wallconfig wallfilterconfig()
@bean(name = "wallfilter")
@dependson("wallconfig")
wallfilter wallfilter(wallconfig wallconfig)
Druid資料來源的配置
druid可以監控資料庫訪問效能,統計sql 的執行效能,提供了乙個高效 功能強大 可擴充套件性好的資料庫連線池。還提供資料庫密碼加密,直接把資料庫密碼寫在配置檔案中,這是不好的行為,容易導致安全問題。druiddruiver 和druiddatasource 都支援passwordcallback...
SpringBoot 配置Druid資料來源
新增相應的依賴 org.springframework.bootgroupid spring boot starter jdbcartifactid dependency com.alibabagroupid druidartifactid 1.1.12version dependency 將資料來...
Springboot配置Druid資料來源
1.匯入druid依賴 com.alibaba druid 1.1.24 2.在yml配置檔案中生命typespring datasource type com.alibaba.druid.pool.druiddatasource我們在pom中匯入我們的druid資料來源的依賴之後,我們需要在yml...