八个比特 2025-02-16 12:03 采纳率: 0%
浏览 31

MybatisPlus微服务模式下连接失败错误

报错日志:
11:47:56:136 ERROR 15472 --- [nio-8082-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.PersistenceException:
'### Error querying database. Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Failed to obtain JDBC Connection; nested exception is java.sql.SQLNonTransientConnectionException: Could not create connection to database server. Attempted reconnect 3 times. Giving up.
'### The error may exist in com/hmall/item/mapper/ItemMapper.java (best guess)
'### The error may involve com.hmall.item.mapper.ItemMapper.selectBatchIds
'### The error occurred while executing a query
'### Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Failed to obtain JDBC Connection; nested exception is java.sql.SQLNonTransientConnectionException: Could not create connection to database server. Attempted reconnect 3 times. Giving up.] with root cause

问题描述:微服务模式下其他的服务都能连接到数据库获取数据,就这个模块获取不到数据。检查了相关配置也没看出来毛病。求解决思路。

配置如下

spring:
  datasource:
    url: jdbc:mysql://${hm.db.host}:3307/hmall?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&serverTimezone=Asia/Shanghai
    driver-class-name: com.mysql.cj.jdbc.Driver
    username: root
    password: ${hm.db.pw}
mybatis-plus:
  configuration:
    default-enum-type-handler: com.baomidou.mybatisplus.core.handlers.MybatisEnumTypeHandler
  global-config:
    db-config:
      update-strategy: not_null
      id-type: auto
  • 写回答

6条回答 默认 最新

  • 阿里嘎多学长 2025-02-16 12:03
    关注

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

    问题解答

    MybatisPlus微服务模式下连接失败错误

    您的问题中没有提供具体的错误信息,但是根据报错日志,可能是MybatisPlus连接数据库失败导致的错误。

    在MybatisPlus微服务模式下,可能会出现以下几种情况导致连接失败:

    1. 数据库连接字符串错误:请检查您的数据库连接字符串是否正确,是否包含了正确的用户名、密码、数据库名、端口号等信息。
    2. 数据库连接超时:可能是数据库连接超时导致的错误,导致MybatisPlus无法连接到数据库。可以尝试增加连接超时时间或使用连接池来解决这个问题。
    3. 数据库服务器错误:可能是数据库服务器出现错误,导致MybatisPlus无法连接到数据库。可以尝试检查数据库服务器的日志是否有相关错误信息。

    解决方案:

    1. 检查数据库连接字符串是否正确。
    2. 尝试增加连接超时时间或使用连接池。
    3. 检查数据库服务器的日志是否有相关错误信息。

    如果您需要更多帮助,请提供更多的错误信息和代码,我的答主将尽力帮助您解决问题。

    评论

报告相同问题?

问题事件

  • 创建了问题 2月16日