Skip to content

sharding-jdbc-spring-boot-starter使用druid,DataSourceUtil初始化数据库连接参数BUG #423

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
ilevon opened this issue Oct 25, 2017 · 1 comment

Comments

@ilevon
Copy link

ilevon commented Oct 25, 2017

你好:

   使用springboot+mybatis+sjdbc时发现了一个问题,供大家参考,如该问题已知,请忽略

版本信息
sharding-jdbc.version:2.0.0.M1
mybatis-spring-boot-starter:1.3.1
druid: 1.0.13
部分源码:
-->io.shardingjdbc.spring.boot.SpringBootConfiguration#setDataSourceMap
-->DataSource dataSource = DataSourceUtil.getDataSource(dataSourceProps.get("type").toString(), dataSourceProps);

--> io.shardingjdbc.core.util.DataSourceUtil#callSetterMethod
--> Method method = dataSource.getClass().getDeclaredMethod(methodName, new Class[]{each});

原因排查:
druid1.0.13版本 com.alibaba.druid.pool.DruidDataSource 自身不包含url、driveClass、password、username等属性,而是在其继承的抽象类DruidAbstractDataSource中。
而shardingjdbc中DataSourceUtil使用的是getDeclaredMethod方式,导致连接参数set不进去,datasource无法正常完成初始化,导致后续代码空指针。

最后解决方式:
改用dbcp连接池可正常使用

@terrymanu
Copy link
Member

duplicate with #404

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants