Closed jameszhongsq closed 4 years ago
datanode name like : ds_x1.tb_x1
datasource.names=m1
please check sharding result datasource name, it not is db/table name.
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
config doc url: https://shardingsphere.apache.org/document/legacy/4.x/document/cn/manual/sharding-jdbc/configuration/config-spring-boot/
exist course_202008 in course_db?
去掉: 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
version
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'