apache / shardingsphere

Distributed SQL transaction & query engine for data sharding, scaling, encryption, and more - on any database.
Apache License 2.0
19.87k stars 6.73k forks source link

java.lang.IllegalStateException: Missing the data source name #6657

Closed jameszhongsq closed 4 years ago

jameszhongsq commented 4 years ago

version

org.apache.shardingsphere sharding-jdbc-spring-boot-starter 4.0.0-RC1

This is the properties configuration

spring.shardingsphere.datasource.names=m1

spring.main.allow-bean-definition-overriding=true

spring.shardingsphere.datasource.m1.type=com.zaxxer.hikari.HikariDataSource spring.shardingsphere.datasource.m1.driver-class-name=com.mysql.cj.jdbc.Driver spring.shardingsphere.datasource.m1.jdbc-url=jdbc:mysql://localhost:3306/course_db?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT spring.shardingsphere.datasource.m1.username=root spring.shardingsphere.datasource.m1.password=root

spring.shardingsphere.sharding.tables.course.database-strategy.standard.sharding-column=create_time spring.shardingsphere.sharding.tables.course.database-strategy.standard.precise-algorithm-class-name=com.shardingjdbcdemo.config.CourseTableShardingAlgorithm spring.shardingsphere.sharding.tables.course.database-strategy.standard.range-algorithm-class-name=com.shardingjdbcdemo.config.CourseTableShardingAlgorithm

spring.shardingsphere.sharding.tables.course.actual-data-nodes=m1.course_${202001..202008}

spring.shardingsphere.sharding.tables.course.key-generator.column=cid spring.shardingsphere.sharding.tables.course.key-generator.type=SNOWFLAKE

spring.shardingsphere.sharding.tables.course.table-strategy.inline.sharding-column=createtime spring.shardingsphere.sharding.tables.course.table-strategy.inline.algorithm-expression=course${202001..202008}

spring.shardingsphere.props.sql.show=true

The database has been created course_202008 table,Error inserting datagram: org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.PersistenceException:

Error updating database. Cause: java.lang.IllegalStateException: Missing the data source name: 'course_202008'

The error may involve com.atguigu.shardingjdbcdemo.mapper.CourseMapper.insert-Inline

The error occurred while setting parameters

SQL: INSERT INTO course ( cname, user_id, cstatus, create_time ) VALUES ( ?, ?, ?, ? )

Cause: java.lang.IllegalStateException: Missing the data source name: 'course_202008'

xiangtao123 commented 4 years ago
  1. datanode name like : ds_x1.tb_x1

  2. datasource.names=m1

  3. please check sharding result datasource name, it not is db/table name.

  4. please check database and table sharding algorithm was the same one? spring.shardingsphere.sharding.tables.course.database-strategy.standard.precise-algorithm-class-name=com.shardingjdbcdemo.config.CourseTableShardingAlgorithm

  5. config doc url: https://shardingsphere.apache.org/document/legacy/4.x/document/cn/manual/sharding-jdbc/configuration/config-spring-boot/

yu199195 commented 4 years ago

exist course_202008 in course_db?

jameszhongsq commented 4 years ago

去掉: spring.shardingsphere.sharding.tables.course.table-strategy.inline.sharding-column=createtime spring.shardingsphere.sharding.tables.course.table-strategy.inline.algorithm-expression=course${202001..202008} 下面的配置:database-strategy改为table-strategy就ok了。 spring.shardingsphere.sharding.tables.course.database-strategy.standard.sharding-column=create_time spring.shardingsphere.sharding.tables.course.database-strategy.standard.precise-algorithm-class-name=com.shardingjdbcdemo.config.CourseTableShardingAlgorithm spring.shardingsphere.sharding.tables.course.database-strategy.standard.range-algorithm-class-name=com.shardingjdbcdemo.config.CourseTableShardingAlgorithm