栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

ShardingSphere-JDBC异常: no table route info

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

ShardingSphere-JDBC异常: no table route info

错误代码:Cause: java.lang.IllegalStateException: no table route info

### The error may involve com.huohuo.sharding.mapper.CourseMapper.insert-Inline
### The error occurred while setting parameters
### SQL: INSERT INTO course  ( id, name, type, status )  VALUES  ( ?, ?, ?, ? )
### Cause: java.lang.IllegalStateException: no table route info


我们看日志记录可以看到JDBC配置tables如下:

tables:
  course:
    actualDataNodes: m1.course_$->{1..2}
    keyGenerator:
      column: id
      props:
        worker.id: '1'
      type: SNOWFLAKE
    logicTable: course
    tableStrategy:
      inline:
        algorithmexpression: m1.course_$->{status.toInteger()%2+1}
        shardingColumn: status
  user:
    actualDataNodes: m1.user_$->{1..2}
    keyGenerator:
      column: id
      props:
        worker.id: '1'
      type: SNOWFLAKE
    logicTable: user
    tableStrategy:
      inline:
        algorithmexpression: m1.user_$->{status.toInteger()%2+1}
        shardingColumn: status

到底哪里出了问题???看配置文件配置,找了半天不晓得哪里的问题,最终也只是把algorithm-expression的value改动了一下,之前是m1. 然后把这个去掉就执行成功了。

#actual-data-nodes course这个逻辑表对应的真实的表分布 m1.course_1 m1.course_2
spring.shardingsphere.sharding.tables.course.actual-data-nodes=m1.course_$->{1..2}
#主键生成策略 对cid进行一下生成,采用了雪花算法 SNOWFLAKE;对worker.id可不配置,有默认值
spring.shardingsphere.sharding.tables.course.key-generator.column=id
spring.shardingsphere.sharding.tables.course.key-generator.type=SNOWFLAKE
spring.shardingsphere.sharding.tables.course.key-generator.props.worker.id=1
spring.shardingsphere.sharding.tables.course.table-strategy.inline.sharding-column=status
spring.shardingsphere.sharding.tables.course.table-strategy.inline.algorithm-expression=course_$->{status.toInteger()%2+1}


spring.shardingsphere.sharding.tables.user.actual-data-nodes=m1.user_$->{1..2}
spring.shardingsphere.sharding.tables.user.key-generator.column=id
spring.shardingsphere.sharding.tables.user.key-generator.type=SNOWFLAKE
spring.shardingsphere.sharding.tables.user.key-generator.props.worker.id=1
spring.shardingsphere.sharding.tables.user.table-strategy.inline.sharding-column=status
spring.shardingsphere.sharding.tables.user.table-strategy.inline.algorithm-expression=user_$->{status.toInteger()%2+1}

error报错就是:没有表路由信息,不知道锁定那张表,但是就是一个库m1,为何加上m1就不行呢?
目前觉得因为是分表配置,无需加上相关变动value,当执行分库策略时候,就不得不加上前缀了。

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/716687.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号