Spring Boot连接MariaDB报错:无法确定合适的驱动类
Spring Boot 连接 MariaDB 启动失败的解决方案
问题场景
配置的application.properties内容:
#mariaDB Connection spring.datasource.url=jdbc:mariadb://localhost:3306/database spring.datasource.username=root spring.datasource.password= spring.datasource.driver-class-name=org.mariadb.jdbc.Driver spring.jpa.hibernate.ddl-auto=create-drop
启动应用时出现错误:
*************************** 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).
当前引入的Maven依赖:
<!-- =============== == MariaDB =============== --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-jpa</artifactId> </dependency> <dependency> <groupId>org.mariadb.jdbc</groupId> <artifactId>mariadb-java-client</artifactId> <version>1.5.7</version> </dependency>
修复步骤
更新MariaDB驱动依赖版本:
mariadb-java-client1.5.7版本过于陈旧,易与当前Spring Boot版本出现兼容性问题。移除手动指定的<version>标签,让Spring Boot依赖管理自动适配兼容版本:<dependency> <groupId>org.mariadb.jdbc</groupId> <artifactId>mariadb-java-client</artifactId> </dependency>修正数据源配置:
- 将
spring.datasource.url中的database替换为本地MariaDB中已创建的真实数据库名称; - 删除
spring.datasource.driver-class-name配置,Spring Boot会根据URL自动识别对应驱动类,避免手动配置的类路径不匹配问题。
修改后的配置示例:
#mariaDB Connection spring.datasource.url=jdbc:mariadb://localhost:3306/your_actual_db_name spring.datasource.username=root spring.datasource.password= spring.jpa.hibernate.ddl-auto=create-drop- 将
验证基础环境:
- 确认本地MariaDB服务已启动,端口3306处于正常监听状态;
- 检查
application.properties是否放置在src/main/resources目录下,确保Spring Boot能正确加载配置。
内容的提问来源于stack exchange,提问作者Leon
相关产品推荐
相关产品推荐

