Skip to content

springboot2.1.1 with mybatis,druid dataSource duplicate #1900

Closed
@imhager

Description

@imhager

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.

Activity

imhager

imhager commented on Feb 20, 2019

@imhager
Author

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

imhager commented on Feb 21, 2019

@imhager
Author

After testing, sharding-jdbc-spring-boot-starter:3.1.0 does not support spring-boot 2.x, so sad.

KomachiSion

KomachiSion commented on Feb 21, 2019

@KomachiSion
Member

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

imhager commented on Feb 21, 2019

@imhager
Author

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.

When is the 2.1.x version supported?

KomachiSion

KomachiSion commented on Feb 21, 2019

@KomachiSion
Member

@imhager,
As my test, ShardingSphere supports 2.1.1.RELEASE spring boot.
The error because the conflict with druid-spring-boot-starter and sharding-jdbc-spring-boot-starter

KomachiSion

KomachiSion commented on Feb 21, 2019

@KomachiSion
Member

You can use spring.main.allow-bean-definition-overriding=true configuration to resolve this error

KomachiSion

KomachiSion commented on Feb 22, 2019

@KomachiSion
Member

You can use spring.main.allow-bean-definition-overriding=true configuration to resolve this error

@imhager. Can this configuration solve your problem? If still has questions, please let us know.

imhager

imhager commented on Feb 25, 2019

@imhager
Author

You can use spring.main.allow-bean-definition-overriding=true configuration to resolve this error

@imhager. Can this configuration solve your problem? If still has questions, please let us know.

thank you for your help.

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.

Action:

Consider renaming one of the beans or enabling overriding by setting spring.main.allow-bean-definition-overriding=true

if i set this value, shardingjdbc/SpringBootConfiguration.DataSource and DruidDataSourceAutoConfigure.DataSource will not affect each other, is it?

KomachiSion

KomachiSion commented on Feb 25, 2019

@KomachiSion
Member

No, DruidDataSourceAutoConfigure.DataSource will be override by shardingjdbc/SpringBootConfiguration.DataSource.
It means the bean 'dataSource' will be created by shardingjdbc/SpringBootConfiguration.DataSource instead of DruidDataSourceAutoConfigure.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

imhager commented on Feb 26, 2019

@imhager
Author

No, DruidDataSourceAutoConfigure.DataSource will be override by shardingjdbc/SpringBootConfiguration.DataSource.
It means the bean 'dataSource' will be created by shardingjdbc/SpringBootConfiguration.DataSource instead of DruidDataSourceAutoConfigure.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?

thanks ,i'll try my test.

KomachiSion

KomachiSion commented on Mar 4, 2019

@KomachiSion
Member

@imhager, have any progress for this issue? If no feedback, we will close this issue tomorrow.

KomachiSion

KomachiSion commented on Mar 5, 2019

@KomachiSion
Member

If no response more than 7 days , we will close it.

leyou240

leyou240 commented on Jun 26, 2019

@leyou240

@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

KomachiSion commented on Jun 27, 2019

@KomachiSion
Member

@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

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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

    Development

    No branches or pull requests

      Participants

      @terrymanu@imhager@leyou240@KomachiSion

      Issue actions

        springboot2.1.1 with mybatis,druid dataSource duplicate · Issue #1900 · apache/shardingsphere