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

克隆GitHub上的Spring Boot项目后启动报错:无法确定合适驱动类

Spring Boot项目克隆后启动数据源配置错误排查

错误信息

Error starting ApplicationContext. To display the condition evaluation report re-run your application with 'debug' enabled.
2023-01-30T11:06:31.614+05:30 ERROR 2060 --- [           main] o.s.b.d.LoggingFailureAnalysisReporter   : 

***************************
APPLICATION FAILED TO START
***************************

Description:

Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.

Reason: Failed to determine a suitable driver class


Action:

Consider the following:
    If you want an embedded database (H2, HSQL or Derby), please put it on the classpath.
    If you have database settings to be loaded from a particular profile you may need to activate it (no profiles are currently active).

排查与解决步骤

  • 确认MySQL驱动依赖
    检查pom.xml中是否包含MySQL驱动依赖,确保版本匹配(MySQL 8.x用com.mysql.cj.jdbc.Driver,5.x用com.mysql.jdbc.Driver):

    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <version>8.0.33</version>
        <scope>runtime</scope>
    </dependency>
    

    若使用Spring Boot Starter,确保spring-boot-starter-data-jpa未排除驱动依赖。

  • 补全数据源配置
    在application.properties中补充完整的数据库连接信息,不要只配置url:

    spring.datasource.url=jdbc:mysql://localhost:3306/project_managementapp?useSSL=false&serverTimezone=UTC
    spring.datasource.username=你的数据库用户名
    spring.datasource.password=你的数据库密码
    spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
    

    直接替换${MYSQL_HOST:localhost}为localhost,避免环境变量影响测试。

  • 验证配置文件位置
    确认application.properties位于src/main/resources目录下,构建后检查target/classes目录中是否存在该文件,确保配置被正确打包。

  • 检查数据库状态
    确认本地MySQL服务已启动,端口3306正常开放,手动用数据库客户端(如MySQL命令行、Navicat)连接project_managementapp数据库,验证连接可用性。

  • 排查多环境Profile
    若项目使用多环境配置文件(如application-dev.properties),需激活对应Profile:

    • 启动时添加VM参数:-Dspring.profiles.active=dev
    • 或在application.properties中设置:spring.profiles.active=dev

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.02 22:35:31