You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Spring Boot 2.7.5中spring.datasource.platform配置失效求助

问题解答

1. spring.datasource.platform是否已被废弃?

是的,该配置项在Spring Boot 2.5及以上版本已被废弃。从2.5版本开始,Spring Boot将数据库初始化相关配置统一迁移到spring.sql.init命名空间下,原spring.datasource下的初始化配置不再生效。

2. 如何配置以运行schema-mysql.sql?

只需修改application.properties中的配置,替换为新的命名空间参数即可:

  • 替换原废弃配置:
    # 旧的废弃配置
    # spring.datasource.platform=mysql
    
    改为:
    spring.sql.init.platform=mysql
    
  • 确保schema-mysql.sql和data-mysql.sql放置在classpath根目录(如src/main/resources下),Spring Boot会自动根据platform值匹配对应后缀的脚本。
  • 若脚本不在默认位置,可通过以下配置指定路径:
    spring.sql.init.schema-locations=classpath:schema-mysql.sql
    spring.sql.init.data-locations=classpath:data-mysql.sql
    
  • 若需强制执行脚本(默认仅在数据库为空时执行),可配置初始化模式:
    spring.sql.init.mode=always
    

内容的提问来源于stack exchange,提问作者Ricardo Costa

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.12 00:35:23