CQller 2025-06-10 18:34 采纳率: 0%
浏览 131

高版本springboot3.x和mybatis-plus的兼容问题


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).

遇到了一个这样的问题,微服务springCloud的项目需要升级jdk1.8到jdk17,springboot同样由2.3.2升级到3.1,因为以前是用的mybatis-plus 3.4.2,升级到了3.5.6,当mybatis-plus升级后,就一直报这个错误。经过排查,gateway网关是可以正常启动的,微服务service1,在以前低版本的时候也可以正常启动,目前感觉是mybatis-plus不兼容引起的问题,因为之前无论哪个服务,同样的nacos和本地配置都是可以正常启动服务的。但当我升级后,网关可正常启动,一给网关加上mysql-connector-j的依赖jar,马上也报错这个问题,有没有兄弟帮忙解答一下

  • 写回答

6条回答 默认 最新

  • 阿里嘎多学长 2025-06-10 18:34
    关注

    阿里嘎多学长整理AIGC生成,因移动端显示问题导致当前答案未能完全显示,请使用PC端查看更加详细的解答过程

    问题解答

    你遇到的问题是 Spring Boot 3.x 和 MyBatis-Plus 的兼容问题,具体来说是无法配置数据源。

    解决方案

    1. 检查 application.propertiesapplication.yml 文件中的数据库连接信息,确保 url 属性正确。
    2. 如果使用 HikariCP 数据源,请检查 spring.datasource.url 属性是否正确。
    3. 如果使用 Tomcat 数据源,请检查 spring.datasource.url 属性是否正确。
    4. 如果你使用的是 MyBatis-Plus 3.x,请检查 mybatis-plus.configuration.config-location 属性是否正确。
    5. 如果你使用的是 Spring Boot 3.x,请检查 spring-boot-starter-jdbcmybatis-spring-boot-starter 两个依赖项是否正确。

    核心代码

    spring:
      datasource:
        url: jdbc:mysql://localhost:3306/mydb
        username: root
        password: password
        driver-class-name: com.mysql.cj.jdbc.Driver
    
    <dependency>
        <groupId>com.baomidou</groupId>
        <artifactId>mybatis-plus-spring-boot-starter</artifactId>
        <version>3.4.3</version>
    </dependency>
    

    如果你遇到其他问题,请提供更多的错误信息和代码,我将尽力帮助你解决问题。

    评论

报告相同问题?

问题事件

  • 创建了问题 6月10日