-
Notifications
You must be signed in to change notification settings - Fork 6.8k
Description
Bug Report
Which version of ShardingSphere did you use?
ShardingSphere-JDBC5.5.2
druid: 1.2.25
Which project did you use? ShardingSphere-JDBC or ShardingSphere-Proxy?
ShardingSphere-JDBC
Expected behavior
When using Nacos as the configuration center in Cluster mode, ShardingSphere-JDBC should correctly initialize the Druid DataSource and recognize the dbType
field without any exceptions.
Actual behavior
With the following configuration:
mode:
type: Cluster
repository:
type: Nacos
When using a Druid DataSource and setting dbType: "mysql"
as a string, an exception occurs during DataSource initialization. The system seems to invoke the following method:
public void setDbType(DbType dbType)
But the actual value passed is a String
("mysql"
), which leads to a type mismatch or runtime error.
Reason analyze (If you can)
When ShardingSphere loads the configuration from Nacos, the value of dbType
is preserved as a String
. However, during reflective invocation, it mistakenly calls:
public void setDbType(DbType dbType)
instead of:
public void setDbType(String dbType)
This causes incompatibility or failure in initializing the Druid DataSource.
Druid defines both overloaded methods:
public void setDbType(DbType dbType) {
this.dbTypeName = dbType == null ? null : dbType.name();
}
public void setDbType(String dbType) {
this.dbTypeName = dbType;
}
ShardingSphere incorrectly resolves the method to call when only a string value ("mysql"
) is provided through configuration center.
Steps to reproduce the behavior
- Use Druid as DataSource;
- Use Nacos as configuration repository with Cluster mode;
- Set
dbType: "mysql"
in the configuration; - Start the application;
- Observe failure in DataSource initialization.
Example codes for reproduce this issue
Sample configuration:
mode:
type: Cluster
repository:
type: Nacos
dataSources:
ds_0:
dataSourceClassName: com.alibaba.druid.pool.DruidDataSource
driverClassName: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost:3306/demo_ds_0
username: root
password: root
dbType: "mysql"
This leads to a type mismatch when calling setDbType(DbType)
with a string value.

