agoodcoolman opened a new issue #13700:
URL: https://github.com/apache/shardingsphere/issues/13700
## Question
I have searched google.
my spring boot version: 2.5.1
sharding-jdbc version 5.0.0
my ymal config file config-sharding.yaml:
`schemaName: sharding_db
dataSources:
ds0:
dataSourceClassName: com.zaxxer.hikari.HikariDataSource
driverClassName: com.microsoft.sqlserver.jdbc.SQLServerDriver
jdbc-url:
connectionTimeoutMilliseconds: 30000
username:
password:
ds1:
dataSourceClassName: com.zaxxer.hikari.HikariDataSource
driverClassName: com.microsoft.sqlserver.jdbc.SQLServerDriver
jdbc-url:
username: sa
password:
rules:
tables:
data_door_info_all:
actual-data-nodes: ds${[0,1]}.data_door_info_all_$->{[0,1,2,3]}
databaseStrategy:
standard:
sharding-column: id
shardingAlgorithmName: hash_mode
table-strategy:
standard:
sharding-column: idcard
sharding-algorithm-name: hash_mode
defaultTableStrategy:
none:
shardingAlgorithms:
hash_mod:
type: MOD
props:
sharding-count: 3
# keyGenerators:
# snowflake:
# type: SNOWFLAKE
# props:
# worker-id: 123
mode:
type: memory`
when i use this code, it happen error 。
`my code
File file = ResourceUtils.getFile("classpath:config-sharding.yaml");
return YamlShardingSphereDataSourceFactory.createDataSource(file);`
exception code:
`Error starting ApplicationContext. To display the conditions report re-run
your application with 'debug' enabled.
15:18:42.497 [main] ERROR org.springframework.boot.SpringApplication -
Application run failed
org.springframework.beans.factory.UnsatisfiedDependencyException: Error
creating bean with name 'dataSourceScriptDatabaseInitializer' defined in class
path resource
[org/springframework/boot/autoconfigure/sql/init/DataSourceInitializationConfiguration.class]:
Unsatisfied dependency expressed through method
'dataSourceScriptDatabaseInitializer' parameter 0; nested exception is
org.springframework.beans.factory.BeanCreationException: Error creating bean
with name 'getDataSource' defined in class path resource
[cn/whmf/wcbigdataweb/Configure.class]: Bean instantiation via factory method
failed; nested exception is
org.springframework.beans.BeanInstantiationException: Failed to instantiate
[javax.sql.DataSource]: Factory method 'getDataSource' threw exception; nested
exception is java.lang.ClassCastException: java.lang.String cannot be cast to
org.apache.shardingsphere.infra.yaml.config.pojo.YamlRuleConfiguration
at
org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:800)
at
org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:541)
at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1334)
at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1177)
at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:564)
at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:524)
at
org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335)
at
org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234)
at
org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333)
at
org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208)
at
org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:322)
at
org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208)
at
org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1154)
at
org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:908)
at
org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:583)
at
org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:145)
at
org.springframework.boot.SpringApplication.refresh(SpringApplication.java:754)
at
org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:434)
at
org.springframework.boot.SpringApplication.run(SpringApplication.java:338)
at
org.springframework.boot.SpringApplication.run(SpringApplication.java:1343)
at
org.springframework.boot.SpringApplication.run(SpringApplication.java:1332)
at
cn.whmf.wcbigdataweb.WcbigdatawebpsqlApplication.main(WcbigdatawebpsqlApplication.java:14)
Caused by: org.springframework.beans.factory.BeanCreationException: Error
creating bean with name 'getDataSource' defined in class path resource
[cn/whmf/wcbigdataweb/Configure.class]: Bean instantiation via factory method
failed; nested exception is
org.springframework.beans.BeanInstantiationException: Failed to instantiate
[javax.sql.DataSource]: Factory method 'getDataSource' threw exception; nested
exception is java.lang.ClassCastException: java.lang.String cannot be cast to
org.apache.shardingsphere.infra.yaml.config.pojo.YamlRuleConfiguration
at
org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:658)
at
org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:486)
at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1334)
at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1177)
at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:564)
at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:524)
at
org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335)
at
org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234)
at
org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333)
at
org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208)
at
org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:276)
at
org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1380)
at
org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1300)
at
org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:887)
at
org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:791)
... 21 common frames omitted
Caused by: org.springframework.beans.BeanInstantiationException: Failed to
instantiate [javax.sql.DataSource]: Factory method 'getDataSource' threw
exception; nested exception is java.lang.ClassCastException: java.lang.String
cannot be cast to
org.apache.shardingsphere.infra.yaml.config.pojo.YamlRuleConfiguration
at
org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185)
at
org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:653)
... 35 common frames omitted
Caused by: java.lang.ClassCastException: java.lang.String cannot be cast to
org.apache.shardingsphere.infra.yaml.config.pojo.YamlRuleConfiguration
at
java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193)
at java.util.Iterator.forEachRemaining(Iterator.java:116)
at
java.util.Spliterators$IteratorSpliterator.forEachRemaining(Spliterators.java:1801)
at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:481)
at
java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471)
at
java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:708)
at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
at
java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:499)
at
org.apache.shardingsphere.infra.yaml.config.swapper.YamlRuleConfigurationSwapperEngine.swapToRuleConfigurations(YamlRuleConfigurationSwapperEngine.java:64)
at
org.apache.shardingsphere.driver.api.yaml.YamlShardingSphereDataSourceFactory.createDataSource(YamlShardingSphereDataSourceFactory.java:131)
at
org.apache.shardingsphere.driver.api.yaml.YamlShardingSphereDataSourceFactory.createDataSource(YamlShardingSphereDataSourceFactory.java:61)
at cn.whmf.wcbigdataweb.Configure.getDataSource(Configure.java:21)
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:498)
at
org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154)
... 36 common frames omitted
Disconnected from the target VM, address: '127.0.0.1:50988', transport:
'socket'
Process finished with exit code 1
`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]