Cannot find table rule and default data source with logic table
来源:互联网 发布:php高并发实战 编辑:程序博客网 时间:2024/06/07 05:49
今天在使用sharding-jdbc整合读写分离的时候报了这么一个错误,Cannot find table rule and default data source with logic table
意思非常明显,是不是你没有给这个表设置分片规则
但是这里我不是说的这个
我这里是另外一个问题。
我只整合了读写分离,并没有需要分库分表,所以报了这个错,具体配置后续给出。
Cause: java.lang.IllegalArgumentException: Cannot find table rule and default data source with logic table: 'city' at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30) at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:150) at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:141) at org.apache.ibatis.session.defaults.DefaultSqlSession.selectOne(DefaultSqlSession.java:77) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:433) ... 81 common frames omittedCaused by: java.lang.IllegalArgumentException: Cannot find table rule and default data source with logic table: 'city' at com.dangdang.ddframe.rdb.sharding.router.single.SingleTableRouter.<init>(SingleTableRouter.java:76) at com.dangdang.ddframe.rdb.sharding.router.SQLRouteEngine.routeSQL(SQLRouteEngine.java:142) at com.dangdang.ddframe.rdb.sharding.router.SQLRouteEngine.routeSQL(SQLRouteEngine.java:117) at com.dangdang.ddframe.rdb.sharding.router.PreparedSQLRouter.route(PreparedSQLRouter.java:62) at com.dangdang.ddframe.rdb.sharding.jdbc.ShardingPreparedStatement.routeSQL(ShardingPreparedStatement.java:162) at com.dangdang.ddframe.rdb.sharding.jdbc.ShardingPreparedStatement.execute(ShardingPreparedStatement.java:115) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.apache.ibatis.logging.jdbc.PreparedStatementLogger.invoke(PreparedStatementLogger.java:59) at com.sun.proxy.$Proxy100.execute(Unknown Source) at org.apache.ibatis.executor.statement.PreparedStatementHandler.query(PreparedStatementHandler.java:63) at org.apache.ibatis.executor.statement.RoutingStatementHandler.query(RoutingStatementHandler.java:79) at org.apache.ibatis.executor.SimpleExecutor.doQuery(SimpleExecutor.java:63) at org.apache.ibatis.executor.BaseExecutor.queryFromDatabase(BaseExecutor.java:324) at org.apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:156) at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:109) at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:83) at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:148) ... 88 common frames omitted
OK ,那么是什么原因呢?
根据我一步步跟踪调试,发现实我们没有启用分库分表的时候,他没有根据默认数据源去创建tableRule,所以抛了这个异常,代码在这里
我们没有给我们的shardingRule配置一个默认的数据源。所以才会报错,
解决办法:
在实例化dataSourceRule的时候,指定一个默认的,第二个参数
//这个是是来描述数据源的分布规则的 DataSourceRule dataSourceRule = new DataSourceRule(dataSourceMap,"datasource_0");//设置一个defaultDataSource非常重要
1 0
- Cannot find table rule and default data source with logic table
- Table Find with Key & Table select
- Find out table source in SAP
- [ERROR] Cannot find or open table wu777/processlist from the internal data dictionary of InnoDB tho
- Datatables warning(table id = 'example'): cannot reinitialise data table
- Update one table with the data in another table
- Update one table with the data in another table
- Data Structures with Java—table(1)
- export excel file with using data table
- 4.3 Populating a Table View with Data
- Azure Basic - Insert data into BlockBlob, Table and Queue (with Diagnostic + Azure Storage Explore)
- data.table
- [zt] hashing table and Data Structure tutorial
- DataTables warning (table id = 'data-table-1'): Requested unknown parameter '9' from the data source
- Add column to existing table with default value
- Adding Expressions, Default Values and Constraints to a Table
- mysql Cannot find or open table x/x 及解决办法
- [bootrap datatable]cannot reinitialise data table 的问题
- Retrofit2+Rxjava学习到封装
- Material Designer设计(上)
- jsp语言基础
- Object Detection
- iOS常用的传值方式详解
- Cannot find table rule and default data source with logic table
- FTP上传下载
- python使用sendmail在linux下发送邮件
- ReentrantLock(三):公平锁与非公平锁
- rabbitmq消息和队列持久化
- 前端之工具
- HttpClient使用详解
- 100篇文章回想
- [Leetcode.Array]561. Array Partition I Add to List