Closed
Description
Question
Which version of Sharding-Jdbc do you using?(您使用的Sharding-Jdbc版本为?)
sharding-jdbc-spring-boot-starter:3.1.0
springboot: 2.1.1.release
druid-spring-boot-starter:1.1.10
mybatis-spring-boot-starter:1.3.2
Expected behavior (您预期的结果是)
正常运行
Actual behavior (实际运行的结果是)
The bean 'dataSource', defined duplicate.
Steps to reproduce the behavior (可重现问题的操作步骤)
APPLICATION FAILED TO START
Description:
The bean 'dataSource', defined in class path resource [io/shardingsphere/shardingjdbc/spring/boot/SpringBootConfiguration.class], could not be registered. A bean with that name has already been defined in class path resource [com/alibaba/druid/spring/boot/autoconfigure/DruidDataSourceAutoConfigure.class] and overriding is disabled.
Metadata
Metadata
Assignees
Type
Projects
Milestone
Relationships
Development
No branches or pull requests
Activity
imhager commentedon Feb 20, 2019
sharding.jdbc.datasource.names=ds0
sharding.jdbc.datasource.ds0.type=com.alibaba.druid.pool.DruidDataSource
sharding.jdbc.datasource.ds0.driver-class-name=com.mysql.jdbc.Driver
sharding.jdbc.datasource.ds0.url=jdbc:mysql://127.0.0.1:3306/test?characterEncoding=UTF-8&serverTimezone=GMT%2B8&useUnicode=true&useSSL=false
sharding.jdbc.datasource.ds0.username=root
sharding.jdbc.datasource.ds0.password=123456
#============== 分表 =========
sharding.jdbc.config.sharding.tables.t_user.actual-data-nodes=ds0.t_user_$->{0..1}
sharding.jdbc.config.sharding.tables.t_user.table-strategy.inline.sharding-column=internal_id
sharding.jdbc.config.sharding.tables.t_user.table-strategy.inline.algorithm-expression=user_$->{internal_id.longValue() % 2}
#未配置分片规则的表将通过默认数据源定位
sharding.jdbc.config.sharding.default-data-source-name=ds0
#打印sql
sharding.jdbc.config.sharding.props.sql.show=true
imhager commentedon Feb 21, 2019
After testing, sharding-jdbc-spring-boot-starter:3.1.0 does not support spring-boot 2.x, so sad.
KomachiSion commentedon Feb 21, 2019
We suggest to use ShardingSphere with versions [1.5.0.RELEASE,2.0.0.M1) for spring-boot,
and versions [4.3.6.RELEASE,5.0.0.M1) for spring springframework.
So sorry for the trouble.
imhager commentedon Feb 21, 2019
When is the 2.1.x version supported?
KomachiSion commentedon Feb 21, 2019
@imhager,
As my test, ShardingSphere supports 2.1.1.RELEASE spring boot.
The error because the conflict with
druid-spring-boot-starter
andsharding-jdbc-spring-boot-starter
KomachiSion commentedon Feb 21, 2019
You can use
spring.main.allow-bean-definition-overriding=true
configuration to resolve this errorKomachiSion commentedon Feb 22, 2019
@imhager. Can this configuration solve your problem? If still has questions, please let us know.
imhager commentedon Feb 25, 2019
thank you for your help.
if i set this value, shardingjdbc/SpringBootConfiguration.DataSource and DruidDataSourceAutoConfigure.DataSource will not affect each other, is it?
KomachiSion commentedon Feb 25, 2019
No,
DruidDataSourceAutoConfigure.DataSource
will be override byshardingjdbc/SpringBootConfiguration.DataSource
.It means the bean 'dataSource' will be created by
shardingjdbc/SpringBootConfiguration.DataSource
instead ofDruidDataSourceAutoConfigure.DataSource
.I don't know your situation, so there is no guarantee that it will not affect you.
Would you like try first in test environment? Or describe why you use
DruidDataSourceAutoConfigure.DataSource
?imhager commentedon Feb 26, 2019
thanks ,i'll try my test.
KomachiSion commentedon Mar 4, 2019
@imhager, have any progress for this issue? If no feedback, we will close this issue tomorrow.
KomachiSion commentedon Mar 5, 2019
If no response more than 7 days , we will close it.
leyou240 commentedon Jun 26, 2019
@KomachiSion I encounter same problem and use the configuration you figure out. Works well. But I noticed that . This may be make some problem do not konw.
So I do not think this is the best way.
KomachiSion commentedon Jun 27, 2019
@leyou240, Do you have any idea for this problem?
We prefer you can open a new issue to show your solution.
And We welcome you to subscribe to the dev mailing list and initiate a discussion for this problem.
BTW, this is a closed issue, we should not discuss in here