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

 

posted @ 2018-12-05 11:17  薛定谔病态猫  阅读(2923)  评论(2编辑  收藏  举报