看了下源码应该是初始化时反射的名称对不上。 所以导致jdbc url无法赋值,如果把官网例子中的url改成jdbcUrl才可以跑起来。只不过没详细看源代码。不知道这个定义的名称除了反射给HikariConfig中还有没有其他地方用到了。



配置
sharding:
jdbc:
datasource:
names: ds_master,ds_slave0,ds_slave1
ds_master:
type: com.zaxxer.hikari.HikariDataSource
driver-class-name: com.mysql.jdbc.Driver
url: jdbc:mysql://localhost:3306/yhbj_main?useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai&useSSL=false&zeroDateTimeBehavior=convertToNull&allowMultiQueries=true
username: root
password:
ds_slave0:
type: com.zaxxer.hikari.HikariDataSource
driver-class-name: com.mysql.jdbc.Driver
url: jdbc:mysql://localhost:3306/yhbj_main?useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai&useSSL=false&zeroDateTimeBehavior=convertToNull&allowMultiQueries=true
username: root
password:
ds_slave1:
type: com.zaxxer.hikari.HikariDataSource
driver-class-name: com.mysql.jdbc.Driver
url: jdbc:mysql://localhost:3306/yhbj_main?useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai&useSSL=false&zeroDateTimeBehavior=convertToNull&allowMultiQueries=true
username: root
password:
config:
masterslave:
name: ds_ms
master-data-source-name: ds_master
slave-data-source-names: ds_slave0,ds_slave1
最后报错
Caused by: java.lang.IllegalArgumentException: jdbcUrl is required with driverClassName.
at com.zaxxer.hikari.HikariConfig.validate(HikariConfig.java:893)
at com.zaxxer.hikari.HikariDataSource.getConnection(HikariDataSource.java:94)
at io.shardingsphere.core.jdbc.adapter.AbstractDataSourceAdapter.getDatabaseType(AbstractDataSourceAdapter.java:62)
at io.shardingsphere.core.jdbc.adapter.AbstractDataSourceAdapter.getDatabaseType(AbstractDataSourceAdapter.java:51)
at io.shardingsphere.core.jdbc.adapter.AbstractDataSourceAdapter.
at io.shardingsphere.core.jdbc.core.datasource.MasterSlaveDataSource.
at io.shardingsphere.core.api.MasterSlaveDataSourceFactory.createDataSource(MasterSlaveDataSourceFactory.java:48)
at io.shardingsphere.jdbc.spring.boot.SpringBootConfiguration.dataSource(SpringBootConfiguration.java:67)
at io.shardingsphere.jdbc.spring.boot.SpringBootConfiguration$$EnhancerBySpringCGLIB$$e6e9c19a.CGLIB$dataSource$1(
at io.shardingsphere.jdbc.spring.boot.SpringBootConfiguration$$EnhancerBySpringCGLIB$$e6e9c19a$$FastClassBySpringCGLIB$$f6857956.invoke(
at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228)
at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:358)
at io.shardingsphere.jdbc.spring.boot.SpringBootConfiguration$$EnhancerBySpringCGLIB$$e6e9c19a.dataSource(
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.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:162)
Hello, we prefer use english to discuss issue.
For bug report, we can keep it, but for question, we will close directly.
@terrymanu 我是按照官方文档做的。 发现的是不兼容。 而不是在这问问题。 每个人都需要看源代码才能正常使用请问这算不算bug report?
@An0nymous0 用spring.shardingsphere.datasource.{datasourcename}.jdbcUrl=xxx 就可以了
@An0nymous0 用spring.shardingsphere.datasource.{datasourcename}.jdbcUrl=xxx 就可以了
亲测可行!应该就是每个数据源必须使用各自对URL的变量命名
Most helpful comment
@terrymanu 我是按照官方文档做的。 发现的是不兼容。 而不是在这问问题。 每个人都需要看源代码才能正常使用请问这算不算bug report?