I have a spring boot application configured with an application.yml file. I'm also using an import.sql file to load test data into my application using insert statements.
I want the import.sql to support multiline statements.
I found this similar question with an answer using and application.properties file Spring Mvc Hibernate Encoding/Multi-line import sql
However I can't seem to apply that answer to using my application.yml file which I have tried unsuccessfully to do as below
spring:
jpa:
show-sql: true
hibernate:
hbm2ddl:
import_files_sql_extractor:org.hibernate.tool.hbm2ddl.MultipleLinesSqlCommandExtractor
For reference I found the documentation for this property here https://docs.jboss.org/hibernate/orm/5.2/javadocs/org/hibernate/tool/hbm2ddl/ImportSqlCommandExtractor.html
But I still can't seem to configure it properly. Can anyone help? Thanks
答案 0 :(得分:0)
in application.yml you can add config:
spring:
datasource: classpath:/init.sql
or add @SQL(value = "data.sql") annotation in your test class where data.sql has multiple lines sql commands.
答案 1 :(得分:0)
通过添加属性前缀“ spring.jpa.properties”,我获得了适用于Spring Boot 2的多行import.sql语句。
因此对于application.yml配置,它是:
spring:
jpa:
properties:
hibernate:
hbm2ddl:
import_files_sql_extractor: org.hibernate.tool.hbm2ddl.MultipleLinesSqlCommandExtractor