请教各位:
项目使用springboot3.3.2+shardingsphere5.4.1,pom.xml配置应该是没问题的,在启动的时候,也可以注册数据源,但在执行sql的时候,无法找到数据源,是怎么回事呢??
pom.xml如下:
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.3.2</version>
<dependency>
<groupId>org.apache.shardingsphere</groupId>
<artifactId>shardingsphere-jdbc-core</artifactId>
<version>5.4.1</version>
<exclusions>
<exclusion>
<artifactId>shardingsphere-infra-util</artifactId>
<groupId>org.apache.shardingsphere</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.shardingsphere</groupId>
<artifactId>shardingsphere-infra-spi</artifactId>
<version>5.4.1</version>
</dependency>
<dependency>
<groupId>com.oracle.database.jdbc</groupId>
<artifactId>ojdbc10</artifactId>
<version>19.9.0.0</version>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-spring-boot3-starter</artifactId>
<version>3.5.6</version>
</dependency>
数据源的配置如下:
spring.shardingsphere.mode.type=Memory
spring.shardingsphere.mode.repository.type=Memory
spring.shardingsphere.mode.overwrite=true
spring.shardingsphere.datasource.names=ds0,ds1
spring.shardingsphere.props.sql.show=true
spring.shardingsphere.sharding.default-data-source-name=ds0
spring.shardingsphere.datasource.ds0.driver-class-name=oracle.jdbc.driver.OracleDriver
spring.shardingsphere.datasource.ds0.url=jdbc:oracle:thin:@XXXX:1521/FREE
spring.shardingsphere.datasource.ds0.password=XXXX
spring.shardingsphere.datasource.ds0.username=XXXX
spring.shardingsphere.datasource.ds0.type=com.zaxxer.hikari.HikariDataSource
#
spring.shardingsphere.datasource.ds1.driver-class-name=oracle.jdbc.driver.OracleDriver
spring.shardingsphere.datasource.ds1.jdbc.url=jdbc:oracle:thin:@XXX:1521/FREE
spring.shardingsphere.datasource.ds1.password=XXX
spring.shardingsphere.datasource.ds1.username=XXX
spring.shardingsphere.datasource.ds1.type=com.zaxxer.hikari.HikariDataSource
#
spring.shardingsphere.sharding.tables.user.database-strategy.standard.sharding-column=id
spring.shardingsphere.sharding.tables.user.database-strategy.standard.precise-algorithm-class-name=com.calvin.sharding.strategy.CustomDBPreciseShardingAlgorithm
在运行的时候,是可以找到数据源的,但在执行SQL的时候,找不到,并且自定义分片的类CustomDBPreciseShardingAlgorithm断点也走不进去
2024-08-16 11:31:53.978 [main ] INFO com.zaxxer.hikari.HikariDataSource - HikariPool-1 - Starting...
2024-08-16 11:31:54.280 [main ] INFO com.zaxxer.hikari.pool.HikariPool - HikariPool-1 - Added connection conn0: url=jdbc:h2:mem:4f056d9f-a1f2-4b00-a3b7-02463e65c108 user=SA
2024-08-16 11:31:54.283 [main ] INFO com.zaxxer.hikari.HikariDataSource - HikariPool-1 - Start completed.
org.springframework.jdbc.BadSqlGrammarException:
### Error updating database. Cause: org.h2.jdbc.JdbcSQLSyntaxErrorException: Table "TEST_USER_0" not found (**this database is empty**); SQL statement:
INSERT INTO TEST_USER_0 ( id, username, password ) VALUES ( ?, ?, ? ) [42104-224]
### The error may exist in com/calvin/sharding/mapper/UserMapper.java (best guess)
### The error may involve com.calvin.sharding.mapper.UserMapper.insert
### The error occurred while executing an update
### SQL: INSERT INTO TEST_USER_0 ( id, username, password ) VALUES ( ?, ?, ? )
### Cause: org.h2.jdbc.JdbcSQLSyntaxErrorException: Table "TEST_USER_0" not found (this database is empty); SQL statement:
INSERT INTO TEST_USER_0 ( id, username, password ) VALUES ( ?, ?, ? ) [42104-224]