Springboot启动加载SQL脚本,还有自动建表驼峰式命名的常用配置
最近在研究Springboot 启动加载SQL文件还有,自动建表的问题,脱坑配置如下
spring:
datasource:
type: com.zaxxer.hikari.HikariDataSource
url: jdbc:mysql://localhost:3306/proce?autoReconnect=true&useSSL=false
username: root
password: root
hikari:
data-source-properties:
cachePrepStmts: true
prepStmtCacheSize: 250
prepStmtCacheSqlLimit: 2048
useServerPrepStmts: true
# separator: $ # 定义SQL的结束符
initialization-mode: never # 执行完毕,需要改为never,否则对已存在的表,报错(从 always 改为 never )
schema:
- classpath:sql/data.sql #注意书写方式,-后面有一个空格,classpath:name.sql中间却没有空格
data:
- classpath:sql/schema.sql # 注意横着写,会重复SQL而报错,data: classpath:sql/schema.sql
jpa:
database-platform: org.hibernate.dialect.MySQL5InnoDBDialect
database: MYSQL
show-sql: true
properties:
hibernate.id.new_generator_mappings: true
hibernate.cache.use_second_level_cache: false
hibernate.cache.use_query_cache: false
hibernate.generate_statistics: false
hibernate.hbm2ddl.auto: none # 自动生成建表语句
hibernate:
naming:
physical-strategy: org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl # 取消驼峰式命名