Closed zcqshine closed 5 years ago
Can you provide full stack trace?
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'sqlSessionFactory' defined in class path resource [com/baomidou/mybatisplus/autoconfigure/MybatisPlusAutoConfiguration.class]: Unsatisfied dependency expressed through method 'sqlSessionFactory' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource': Post-processing of FactoryBean's singleton object failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'scopedTarget.dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Hikari.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.zaxxer.hikari.HikariDataSource]: Factory method 'dataSource' threw exception; nested exception is org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException: Failed to determine a suitable driver class
at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:732)
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:474)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1247)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1096)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:535)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:495)
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:317)
at org.springframework.beans.factory.support.AbstractBeanFactory$$Lambda$125/1143135560.getObject(Unknown Source)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:315)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)
at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:251)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1135)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1062)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireByType(AbstractAutowireCapableBeanFactory.java:1421)
... 71 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource': Post-processing of FactoryBean's singleton object failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'scopedTarget.dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Hikari.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.zaxxer.hikari.HikariDataSource]: Factory method 'dataSource' threw exception; nested exception is org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException: Failed to determine a suitable driver class
at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.getObjectFromFactoryBean(FactoryBeanRegistrySupport.java:119)
at org.springframework.beans.factory.support.AbstractBeanFactory.getObjectForBeanInstance(AbstractBeanFactory.java:1645)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.getObjectForBeanInstance(AbstractAutowireCapableBeanFactory.java:1175)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:327)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)
at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:251)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1135)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1062)
at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:818)
at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:724)
... 85 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'scopedTarget.dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Hikari.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.zaxxer.hikari.HikariDataSource]: Factory method 'dataSource' threw exception; nested exception is org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException: Failed to determine a suitable driver class
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:590)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1247)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1096)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:535)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:495)
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$1(AbstractBeanFactory.java:353)
at org.springframework.beans.factory.support.AbstractBeanFactory$$Lambda$338/1571580867.getObject(Unknown Source)
at org.springframework.cloud.context.scope.GenericScope$BeanLifecycleWrapper.getBean(GenericScope.java:390)
at org.springframework.cloud.context.scope.GenericScope.get(GenericScope.java:184)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:350)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)
at org.springframework.aop.target.SimpleBeanTargetSource.getTarget(SimpleBeanTargetSource.java:35)
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:672)
at com.zaxxer.hikari.HikariDataSource$$EnhancerBySpringCGLIB$$474dd6b5.getMetricRegistry(<generated>)
at org.springframework.boot.actuate.autoconfigure.metrics.jdbc.HikariDataSourceMetricsPostProcessor.bindMetricsRegistryToHikariDataSource(HikariDataSourceMetricsPostProcessor.java:60)
at org.springframework.boot.actuate.autoconfigure.metrics.jdbc.HikariDataSourceMetricsPostProcessor.postProcessAfterInitialization(HikariDataSourceMetricsPostProcessor.java:52)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsAfterInitialization(AbstractAutowireCapableBeanFactory.java:431)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.postProcessObjectFromFactoryBean(AbstractAutowireCapableBeanFactory.java:1841)
at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.getObjectFromFactoryBean(FactoryBeanRegistrySupport.java:116)
... 94 more
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.zaxxer.hikari.HikariDataSource]: Factory method 'dataSource' threw exception; nested exception is org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException: Failed to determine a suitable driver class
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185)
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:582)
... 112 more
Caused by: org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException: Failed to determine a suitable driver class
at org.springframework.boot.autoconfigure.jdbc.DataSourceProperties.determineDriverClassName(DataSourceProperties.java:236)
at org.springframework.boot.autoconfigure.jdbc.DataSourceProperties.initializeDataSourceBuilder(DataSourceProperties.java:176)
at org.springframework.boot.autoconfigure.jdbc.DataSourceConfiguration.createDataSource(DataSourceConfiguration.java:43)
at org.springframework.boot.autoconfigure.jdbc.DataSourceConfiguration$Hikari.dataSource(DataSourceConfiguration.java:83)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154)
... 113 more
When debugging, I found that I did not enter the method getDataSource
of SpringBootConfiguration
properties:
spring.shardingsphere.datasource.names = ds
spring.shardingsphere.sharding.default-data-source-name = ds
spring.shardingsphere.datasource.ds.type = com.zaxxer.hikari.HikariDataSource
spring.shardingsphere.datasource.ds.jdbc-url = jdbc:postgresql://192.168.2.29:5432/xxx
spring.shardingsphere.datasource.ds.driver-class-name = org.postgresql.Driver
spring.shardingsphere.datasource.ds.username = xxx
spring.shardingsphere.datasource.ds.password = xxx
...
the exception is throw from:
Error creating bean with name 'sqlSessionFactory' defined in class path resource [com/baomidou/mybatisplus/autoconfigure/MybatisPlusAutoConfiguration.class]: Unsatisfied dependency expressed through method 'sqlSessionFactory' parameter 0;
Can you transfer this issue to com/baomidou/mybatisplus?
sorry I didn't read the error message carefully. I will report this issue to mybatisplus
The develop of MyBatis-plus
consider mabtisplus
can't get driver class from sharding-jdbc
.
I think the HikariDataSource
is not initialized.
I have the same problem but I only use mybatis.
the error stack info:
APPLICATION FAILED TO START
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).
Disconnected from the target VM, address: '127.0.0.1:51648', transport: 'socket'
Process finished with exit code 1
my application.properties is spring.shardingsphere.datasource.names=ds_0,ds_1
spring.shardingsphere.datasource.ds_0.type=com.zaxxer.hikari.HikariDataSource spring.shardingsphere.datasource.ds_0.driver-class-name=com.mysql.jdbc.Driver spring.shardingsphere.datasource.ds_0.jdbc-url=jdbc:mysql://localhost:3306/ds0?serverTimezone=UTC&useSSL=false&useUnicode=true&characterEncoding=UTF-8 spring.shardingsphere.datasource.ds_0.username=root spring.shardingsphere.datasource.ds_0.password=
spring.shardingsphere.datasource.ds_1.type=com.zaxxer.hikari.HikariDataSource spring.shardingsphere.datasource.ds_1.driver-class-name=com.mysql.jdbc.Driver spring.shardingsphere.datasource.ds_1.jdbc-url=jdbc:mysql://localhost:3306/ds1?serverTimezone=UTC&useSSL=false&useUnicode=true&characterEncoding=UTF-8 spring.shardingsphere.datasource.ds_1.username=root spring.shardingsphere.datasource.ds_1.password=
spring.shardingsphere.sharding.default-database-strategy.inline.sharding-column=userid spring.shardingsphere.sharding.default-database-strategy.inline.algorithm-expression=ds$->{user_id % 2}
spring.shardingsphere.sharding.tables.t_order.actual-data-nodes=ds$->{0..1}.t_order spring.shardingsphere.sharding.tables.t_order.key-generator.column=order_id spring.shardingsphere.sharding.tables.t_order.key-generator.type=SNOWFLAKE spring.shardingsphere.sharding.tables.t_order.key-generator.props.worker.id=123 spring.shardingsphere.sharding.tables.t_order_item.actual-data-nodes=ds$->{0..3}.t_order_item spring.shardingsphere.sharding.tables.t_order_item.key-generator.column=order_item_id spring.shardingsphere.sharding.tables.t_order_item.key-generator.type=SNOWFLAKE spring.shardingsphere.sharding.tables.t_order_item.key-generator.props.worker.id=123
spring.shardingsphere.props.sql.show=true
I think the problem must exists, it should be reopened
I think the problem must exists, it should be reopened
I feed this back to MyBatis-plus of developers, they said that its maybe the bug of shardingsphere
I meet the same problem
4.0.0-RC2 I meet the same problem,Normal after removing druid
4.0.0-RC2 I meet the same problem,Normal after removing druid 我用的是hicari,没有用druid一样的是这个问题。请问你现在用的是哪个数据有组件
4.0.0-RC2 I meet the same problem,Normal after removing druid 我用的是hicari,没有用druid一样的是这个问题。请问你现在用的是哪个数据有组件
I also use the hicariCP data source, the configuration read and write separation starts normally, the test is normal, once the configuration data is desensitized, this problem occurs.
Excuse me, is there a solution to this problem
我发现什么原因了,也是被困扰了两天,是因为引入的druid方式错误,
错误引入方式:
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid-spring-boot-starter</artifactId>
<version>${druid.version}</version>
</dependency>
正确引入方式:
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>${druid.version}</version>
</dependency>
尝试过4.0.0-RC1没有问题,mybatis和数据库连接池版本号都未改变。 所以应该还是4.0.0-RC2&4.0.0-RC3的问题。目前有有几种方案:1.ShardingSphere 4.0.0-RC1 搭配 MyBatis、druid-spring-boot-starter使用。 2.ShardingSphere 4.0.0-RC2 或者RC3 搭配 MyBatis、com.alibaba.druid(非springboot版本)使用。 3.希望引起ShardingSphere注意,修复bug
官方这个问题在 4.0.0 还没有修复么?
我在4.0.0版本中使用了mybatis 在非注册中心配置下没有问题,如果引入了sharding-jdbc-orchestration-spring-boot-starter就会报这个错误,比较了sharding-jdbc-orchestration-spring-boot-starter包中的OrchestrationSpringBootConfiguration.java和sharding-jdbc-spring-boot-starter包中的SpringBootConfiguration.java文件,发现少了@AutoConfigureBefore(DataSourceAutoConfiguration.class)这个注解,感觉是这里影响的。
4.0.0还是不行
I have the same problem but I only use mybatis.
the error stack info:
APPLICATION FAILED TO START
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).
Disconnected from the target VM, address: '127.0.0.1:51648', transport: 'socket'
Process finished with exit code 1
my application.properties is spring.shardingsphere.datasource.names=ds_0,ds_1
spring.shardingsphere.datasource.ds_0.type=com.zaxxer.hikari.HikariDataSource spring.shardingsphere.datasource.ds_0.driver-class-name=com.mysql.jdbc.Driver spring.shardingsphere.datasource.ds_0.jdbc-url=jdbc:mysql://localhost:3306/ds0?serverTimezone=UTC&useSSL=false&useUnicode=true&characterEncoding=UTF-8 spring.shardingsphere.datasource.ds_0.username=root spring.shardingsphere.datasource.ds_0.password=
spring.shardingsphere.datasource.ds_1.type=com.zaxxer.hikari.HikariDataSource spring.shardingsphere.datasource.ds_1.driver-class-name=com.mysql.jdbc.Driver spring.shardingsphere.datasource.ds_1.jdbc-url=jdbc:mysql://localhost:3306/ds1?serverTimezone=UTC&useSSL=false&useUnicode=true&characterEncoding=UTF-8 spring.shardingsphere.datasource.ds_1.username=root spring.shardingsphere.datasource.ds_1.password=
spring.shardingsphere.sharding.default-database-strategy.inline.sharding-column=userid spring.shardingsphere.sharding.default-database-strategy.inline.algorithm-expression=ds$->{user_id % 2}
spring.shardingsphere.sharding.tables.t_order.actual-data-nodes=ds$->{0..1}.t_order spring.shardingsphere.sharding.tables.t_order.key-generator.column=order_id spring.shardingsphere.sharding.tables.t_order.key-generator.type=SNOWFLAKE spring.shardingsphere.sharding.tables.t_order.key-generator.props.worker.id=123 spring.shardingsphere.sharding.tables.t_order_item.actual-data-nodes=ds$->{0..3}.t_order_item spring.shardingsphere.sharding.tables.t_order_item.key-generator.column=order_item_id spring.shardingsphere.sharding.tables.t_order_item.key-generator.type=SNOWFLAKE spring.shardingsphere.sharding.tables.t_order_item.key-generator.props.worker.id=123
spring.shardingsphere.props.sql.show=true
您的问题解决了吗
[ShardingSphere 4.1.1 & druid-spring-boot-starter 1.1.22 ] I meet the same problem. When I used druid 1.1.22,not the druid-spring-boot-starter,the problem also exists.
[ShardingSphere 4.1.1 & druid-spring-boot-starter 1.1.22 ] I meet the same problem. When I used druid 1.1.22,not the druid-spring-boot-starter,the problem also exists.
me too
我发现什么原因了,也是被困扰了两天,是因为引入的druid方式错误, 错误引入方式:
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid-spring-boot-starter</artifactId>
<version>${druid.version}</version>
</dependency>
正确引入方式:<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>${druid.version}</version>
</dependency>
this works for me.
我发现什么原因了,也是被困扰了两天,是因为引入的druid方式错误, 错误引入方式:
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid-spring-boot-starter</artifactId>
<version>${druid.version}</version>
</dependency>
正确引入方式:<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>${druid.version}</version>
</dependency>
this works for me.
4.0.0-RC2 I meet the same problem,Normal after removing druid 我用的是hicari,没有用druid一样的是这个问题。请问你现在用的是哪个数据有组件
5.0.0-RC1-SNAPSHOT springboot 2.3.4 HikariCp 3.4.5 init datasource failed.Do you change datasourcepool?
我发现什么原因了,也是被困扰了两天,是因为引入的druid方式错误, 错误引入方式:
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid-spring-boot-starter</artifactId>
<version>${druid.version}</version>
</dependency>
正确引入方式:<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>${druid.version}</version>
</dependency>
this works for me.
this also works for me .
我发现什么原因了,也是被困扰了两天,是因为引入的druid方式错误, 错误引入方式:
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid-spring-boot-starter</artifactId>
<version>${druid.version}</version>
</dependency>
正确引入方式:<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>${druid.version}</version>
</dependency>
This works for me, thanks!
Bug Report
The is no problem in old version. when I upgrade to 4.0.0-RC2 or 4.0.0-RC3-SNAPSHOT, the dataSource can't init
I found the problem may be in class
shardingsphere/shardingjdbc/spring/boot/SpringBootConfiguration.java
can't getdataSource
.