sql - data.sql 不会执行
问题描述
我正在尝试初始化数据库并使用 spring boot 插入一些数据。根据文档,我只需要资源文件夹中的 data.sql 文件来执行我的 sql 初始数据,但由于某种原因,我的 data.sql 被忽略了。
这是我的 application.properties 文件:
spring.jpa.hibernate.ddl-auto=update
spring.datasource.url=jdbc:mysql://${MYSQL_HOST:localhost}:3306/urmamma
spring.datasource.username=root
spring.datasource.password=
spring.session.jdbc.initialize-schema=always
#spring.data.jpa.repositories.bootstrap-mode=default
#spring.datasource.data=classpath:data.sql
我的 data.sql 文件:
insert into user (id, email, name) values (1, '123@gmail.com', 'Teobaldo')
使用 gradle 的依赖项:
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-data-rest'
implementation 'org.springframework.boot:spring-boot-starter-jdbc'
implementation 'org.springframework.boot:spring-boot-starter-oauth2-client'
implementation 'org.springframework.boot:spring-boot-starter-security'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.data:spring-data-rest-hal-explorer'
implementation 'org.springframework.session:spring-session-jdbc'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
runtimeOnly 'mysql:mysql-connector-java'
providedRuntime 'org.springframework.boot:spring-boot-starter-tomcat'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'org.springframework.security:spring-security-test'
}
解决方案
我在这里错过了这个配置:
spring.datasource.initialization-mode=always
在阅读文档时,我把它误认为是财产
spring.session.jdbc.initialize-schema=always
我已经有了。
推荐阅读
- firebase - Firestore 计费和使用 API
- spring-boot - 如何在 thymeleaf 表达式 th:each 中使用 kotlin 表达式?
- swift - AVPlayer seek 后的当前时间不正确
- powershell - 无法使用 powershell export-csv 将错误消息附加到 csv
- exception - system.invalidoperationexception 序列在 system.linq.enumerable.first[TSource]{IEnumaberable`1 source} 处不包含任何元素
- linux - ParaView、Surface pro 6 Linux 中的小图标
- php - CardDAV 从 iCloud 获取所有联系人
- c# - 从字符串中删除点
- firebase - firebase部署功能上的触发功能
- reactjs - 如何模拟输入 onChange 事件,然后模拟点击结果