万网如何建设购物网站,广告素材网站哪个比较好,网站制作建设,中国企业网地址背景
最近在配置数据库的初始化时#xff0c;遇到 sql:init:schema-locations: classpath:db/schema.sqldata-locations: classpath:db/data.sqlusername: sapassword:网上搜索资料#xff0c;大同小异#xff0c;都是无用的资料#xff0c;于是决定自己研究下数据库的初始…背景
最近在配置数据库的初始化时遇到 sql:init:schema-locations: classpath:db/schema.sqldata-locations: classpath:db/data.sqlusername: sapassword:网上搜索资料大同小异都是无用的资料于是决定自己研究下数据库的初始化。于是有了下文。
备注 解决数据库无法正确初始化的问题在于数据库的配置发生了变化详细参考 private static ListString scriptLocations(ListString locations, String fallback, String platform) {if (locations ! null) {return locations;}ListString fallbackLocations new ArrayList();fallbackLocations.add(optional:classpath*: fallback - platform .sql);fallbackLocations.add(optional:classpath*: fallback .sql);return fallbackLocations;}显然当配置错误的时候默认从 classpath 下的
optional:classpath*: fallback - platform .sql
optional:classpath*: fallback .sql取数据而 fallback 为 data 或 schemaplatform 为 all。
因此正确的配置应该是
spring:datasource:schema: classpath:/db/table.sql;/db/table1.sqldata: classpath:/db/data.sqldata-username: saschema-username: saschema-password:data-password:initialization-mode: always其中initialization-mode 必须是 always
配置
DataSourceProperties
数据源初始化
AbstractScriptDatabaseInitializer DataSourceScriptDatabaseInitializer R2dbcScriptDatabaseInitializer
H2 相关配置
H2ConsoleAutoConfiguration H2ConsoleProperties