SpringBoot2.x整合JDBC及初始化data.sql和schema.sql腳本


今天在使用SpringBoot2.x版本整合JDBC時遇到了一些問題;由於我之前一直用SpringBoot1.5的版本,所以直接在yml里按照1.5的版本配置了屬性,沒想到2.x直接不能用了。首先是數據庫驅動改變了:

Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class is `com.mysql.cj.jdbc.Driver'. The driver is automatically registered via the SPI and manual loading of the driver class is
generally unnecessary.


  以前的驅動
jdbc.driverClass = com.mysql.dbc.Driver

現在的驅動

jdbc.driverClass = com.mysql.cj.jdbc.Driver

 

然后是自動初始化sql腳本的問題,1.5的版本只要將腳本命名為schama-*.sql,放在classpath下啟動項目就能自動執行該腳本語句,到了2.x版本則需要增加如下配置:

schema-username: root
schema-password: 123456
data-username: root
data-password: 123456
platform: mysql
schema: classpath:schema-*.sql
continue-on-error: true
initialization-mode: always

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM