shardingsphere icon indicating copy to clipboard operation
shardingsphere copied to clipboard

Use 4.0.1 in spring boot 2.2.2 。get error Failed to configure a DataSource。

Open jaedongjuly opened this issue 6 years ago • 9 comments

I use 4.0.1 in my spring boot 2.2.2

<dependency>
                  <groupId>com.alibaba</groupId>
                  <artifactId>druid-spring-boot-starter</artifactId>
                  <version>1.1.20</version>
</dependency>
 <dependency>
            <groupId>org.apache.shardingsphere</groupId>
            <artifactId>sharding-jdbc-spring-boot-starter</artifactId>
            <version>4.0.1</version>
  </dependency>

But i get error

Description:
Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.
Reason: Failed to determine a suitable driver class
Action:
Consider the following:
	If you want an embedded database (H2, HSQL or Derby), please put it on the classpath.
	If you have database settings to be loaded from a particular profile you may need to activate it (no profiles are currently active).

I change 4.0.0-RC1 version

 <dependency>
            <groupId>org.apache.shardingsphere</groupId>
            <artifactId>sharding-jdbc-spring-boot-starter</artifactId>
            <version>4.0.0-RC1</version>
  </dependency>
<dependency>
                  <groupId>com.alibaba</groupId>
                  <artifactId>druid-spring-boot-starter</artifactId>
                  <version>1.1.20</version>
</dependency>

The error is gone; I think that druid-spring-boot-starter have some wrong. But i don't find reason. What's the reason?

jaedongjuly avatar Jun 05 '20 03:06 jaedongjuly

@jaedongjuly Could you try it again with the latest version?

menghaoranss avatar Jun 05 '20 07:06 menghaoranss

@jaedongjuly Please do not use druid-spring-boot-starter Because it conflicts with the Sharding-datasource

yu199195 avatar Jun 05 '20 08:06 yu199195

@jaedongjuly Could you try it again with the latest version?

I use 4.1.0

  <dependency>
            <groupId>org.apache.shardingsphere</groupId>
            <artifactId>sharding-jdbc-spring-boot-starter</artifactId>
            <version>4.1.0</version>
        </dependency>

and get same

Description:

Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.

Reason: Failed to determine a suitable driver class


Action:

Consider the following:
	If you want an embedded database (H2, HSQL or Derby), please put it on the classpath.
	If you have database settings to be loaded from a particular profile you may need to activate it (no profiles are currently active).

jaedongjuly avatar Jun 05 '20 08:06 jaedongjuly

@jaedongjuly Please do not use druid-spring-boot-starter Because it conflicts with the Sharding-datasource

I guess some wrong with druid-spring-boot-starter too . but i don't find reason . I want to know .

jaedongjuly avatar Jun 05 '20 08:06 jaedongjuly

@jaedongjuly show you configuration,druid datasource property is url ? you config jdbc-url?

yu199195 avatar Jun 05 '20 08:06 yu199195

@jaedongjuly show you configuration,druid datasource property is url ? you config jdbc-url?

spring.shardingsphere.datasource.names=m1
spring.shardingsphere.datasource.m1.type=com.alibaba.druid.pool.DruidDataSource
spring.shardingsphere.datasource.m1.driver-class-name=com.mysql.jdbc.Driver
spring.shardingsphere.datasource.m1.url=jdbc:mysql://localhost:3306/course_db?serverTimezone=UTC&useSSL=false&useUnicode=true&characterEncoding=UTF-8
spring.shardingsphere.datasource.m1.username=root
spring.shardingsphere.datasource.m1.password=
#配置course表
spring.shardingsphere.sharding.tables.course.actual-data-nodes=m1.course_$->{1..2}
#自增列名称,course用自增主键生成器
spring.shardingsphere.sharding.tables.course.key-generator.column=cid
# course 可使用用户自定义的列值生成器或选择内置类型:SNOWFLAKE/UUID
spring.shardingsphere.sharding.tables.course.key-generator.type=SNOWFLAKE
#分片列名称
spring.shardingsphere.sharding.tables.course.table-strategy.inline.sharding-column=cid
#分片算法行表达式,需符合groovy语法
spring.shardingsphere.sharding.tables.course.table-strategy.inline.algorithm-expression=course_$->{cid % 2 + 1}
#是否开启SQL显示,默认值: false
spring.shardingsphere.props.sql.show=true

This is only my application.properties.

jaedongjuly avatar Jun 05 '20 09:06 jaedongjuly

where durid config?

yu199195 avatar Jun 05 '20 13:06 yu199195

where durid config?

I don't write druid config.

I use

<dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>druid</artifactId>
            <version>1.1.20</version>
        </dependency>

instead of

  <dependency>
                  <groupId>com.alibaba</groupId>
                  <artifactId>druid-spring-boot-starter</artifactId>
                  <version>1.1.20</version>
              </dependency>

My demo run well.

jaedongjuly avatar Jun 07 '20 02:06 jaedongjuly

duplicated https://github.com/apache/shardingsphere/issues/5697

kimmking avatar Jun 10 '20 07:06 kimmking