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

Spring Boot连接PostgreSQL报Failed to determine a suitable driver class问题求助

报错根因

核心问题是application.yaml中的数据源、JPA配置没有添加Spring Boot要求的spring前缀,Spring Boot的自动配置类无法识别到你声明的数据库连接信息,误认为未配置数据源,因此尝试加载嵌入式数据库失败,最终触发报错。
次要排查点:

  • application.yaml文件存放位置错误,未放在src/main/resources根目录
  • JPA配置中错误填写了database: my_db属性,该属性用于指定数据库类型而非库名,库名已在JDBC URL中声明,无需额外配置

解决方案

  • 修正application.yaml配置,给所有数据库相关配置增加spring前缀,删除冗余的database配置,修正后内容如下:
spring:
  datasource:
    driver-class-name: org.postgresql.Driver
    url: jdbc:postgresql://localhost:5432/my_db
    username: postgres
    password: pswrd
  # JPA 配置
  jpa:
    hibernate:
      ddl-auto: update # 首次启动项目可改为create,后续切换为update或none避免数据丢失
    show-sql: true
    database-platform: org.hibernate.dialect.PostgreSQLDialect
    open-in-view: false
    generate-ddl: true
  • 确认application.yaml文件存放在src/main/resources根目录下,无文件名拼写错误
  • 刷新Maven依赖,保证PostgreSQL驱动正常加载到项目中,你当前pom.xml中的PostgreSQL依赖配置符合要求,无需修改

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.14 15:06:03