• SpringBoot数据库连接失败解决方案


    1. <dependency>
    2. <groupId>org.mybatis.spring.bootgroupId>
    3. <artifactId>mybatis-spring-boot-starterartifactId>
    4. <version>3.0.2version>
    5. dependency>
    6. <dependency>
    7. <groupId>com.mysqlgroupId>
    8. <artifactId>mysql-connector-jartifactId>
    9. <scope>runtimescope>
    10. dependency>
    11. <dependency>
    12. <groupId>org.springframework.bootgroupId>
    13. <artifactId>spring-boot-starter-webartifactId>
    14. dependency>

    上面的是SpringBoot的Pop.xml数据库框架代码

    SpringBoot是会自动读取配的,就不需要像之前一样配置Mybatis文件了,但是会出现一些奇怪的问题

    例如这些

    2023-11-09T20:42:47.570+08:00  WARN 23284 --- [           main] o.m.s.mapper.ClassPathMapperScanner      : No MyBatis mapper was found in '[com.example.test]' package. Please check your configuration.

    第一种是因为你没有@Mapper这个注释

    错误案例如上图,添加@Mapper注释即可

    No database selected  第二种

     [] threw exception [Request processing failed:

    第三种org.springframework.jdbc.UncategorizedSQLException: 
    ### Error querying database.  Cause: java.sql.SQLException: No database selected

    这两种是数据库选择问题

    错误案例如上,因为没有添加对应的数据库而是直接调用属性

    第三种:Access denied for user '严欣铷'@'localhost' (using password: YES)

    第四种2023-11-09T20:50:20.501+08:00 ERROR 14124 --- [nio-8080-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet]    : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed: org.mybatis.spring.MyBatisSystemException] with root cause
    这个的核心是因为你的配置文件是name而不是USername

    错误案例如下

    改成username就完事了

    完整代码及数据库如下

    注意了yml文件和那个properties文件除了样式没有区别,用法是一样的

    特别注意YML文件  名字 = 这一定要有一个空格 属性

    运行结果如下

    JSON文件的格式

  • 相关阅读:
    RIP,EIGRP,OSPF区别
    自定义MVC增删改查
    国外的SRE都是干啥工作的?薪资如何?
    照片一键换天空怎么弄?不妨试试这三个照片一键换天空方法
    博客后台模块
    基于bat脚本的前端发布流程设计与实现
    WebGL 渲染三维图形作为纹理贴到另一个三维物体表面
    网络基础--1.网络纵横
    【数据结构】二叉树--链式结构的实现 (遍历)
    JAVA枚举
  • 原文地址:https://blog.csdn.net/c_yanxin_ru/article/details/134319817