spring框架,整合連線池,整合junit測試

2021-09-19 13:38:37 字數 2316 閱讀 8062

讓spring知道外部的資料庫連線資訊的配置檔案 jdbc.properties 

讓spring能夠載入jdbc.properties檔案

spring提供了乙個標籤 可以載入外部的properties檔案內容

導context的命名空間和約束 才會有提示

1. 在/spring-framework-4.2.4.release/docs/spring-framework-reference/html/xsd-configuration.html 中找到約束

可配置多個連線池

根據實際需要連線池配置,以鍵值對的方式儲存資料(因為我的mysql是8.0x版本的所有url需要這麼寫)

jdbc.driver=com.mysql.cj.jdbc.driver

jdbc.url=jdbc:mysql://localhost:3306/atm?characterencoding=utf8&usessl=false&servertimezone=utc&rewritebatchedstatements=true

jdbc.username=root

jdbc.password=123

#jdbc.driver=com.mysql.jdbc.driver

#jdbc.url=jdbc:oracle://localhost:3306/hibernate

#jdbc.username=root

#jdbc.password=1234

#jdbc.driver=com.mysql.jdbc.driver

#jdbc.url=jdbc:db2://localhost:3306/hibernate

#jdbc.username=root

#jdbc.password=1234

spring整合junit做測試普通測試的缺點:

**復用性大

配置檔案執行一次載入一次

spinrg整合junit開發步驟:              

1 導包

spring-test.jar 增強

spring-aop.jar 可以寫註解

junit.jar  還是之前的測試

2 要告訴spring誰載入配置檔案 (springjunt4classrunner.class)

3 要告訴spring配置檔案的位址

4 分層測試

//spinrg整合junit開發步驟:

//

// 1 導包

// spring-test.jar 增強

// spring-aop.jar 可以寫註解

// junit.jar 還是之前的測試

// 2 要告訴spring誰載入配置檔案 (springjunt4classrunner.class)

// 3 要告訴spring配置檔案的位址

// 4 分層測試

/*1:告訴spring配置檔案在哪個地方*/

/*2:告訴spring誰載入配置檔案*/

@runwith(value =springjunit4classrunner.class)

public class junit1

}**執行結果:好處,可實現分層測試

spring框架建立連線池

配置檔案 db.properties db connection parameters 配置pom.xml導包 org.springframework spring webmvc 3.2.8.release jstl jstl 1.2junit junit 4.12 com.oracle ojdbc...

Spring整合執行緒池

自己在程式中手動new很容易造成執行緒濫用,建立執行緒也是比較消耗資源的操作,所以建議如果有此需求,將執行緒池統一交給spring框架進行管理。如下 bean id taskexecutor class org.springframework.scheduling.concurrent.thread...

Spring整合執行緒池

threadpoolexecutor.abortpolicy 丟棄任務並丟擲rejectedexecutionexception異常 threadpoolexecutor.discardpolicy 也是丟棄任務,但是不丟擲異常。threadpoolexecutor.discardoldestpol...