GreekPanda opened a new issue, #14238:
URL: https://github.com/apache/shardingsphere/issues/14238
## Bug Report
### Which version of ShardingSphere did you use?
shardingshpere 5.0.0
### Which project did you use? ShardingSphere-JDBC or ShardingSphere-Proxy?
ShardingSphere-JDBC
### Expected behavior
Can read the properties from nacos based on springcloud project successfully
### Actual behavior
Failed to parse properties from nacos
### Reason analyze (If you can)
Maybe confict with springboot starter?
### Steps to reproduce the behavior, such as: SQL to execute, sharding rule
configuration, when exception occur etc.
I've made a sample nacos yml file based on official tutorials and build a
springcloud project using nacos as a register center. Try to do some test like
insert or select opertion. But it shows error:
java.lang.IllegalStateException: Failed to load ApplicationContext
at
org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:125)
at
org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:108)
at
org.springframework.test.context.web.ServletTestExecutionListener.setUpRequestContextIfNecessary(ServletTestExecutionListener.java:190)
at
org.springframework.test.context.web.ServletTestExecutionListener.prepareTestInstance(ServletTestExecutionListener.java:132)
at
org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:246)
at
org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:227)
at
org.springframework.test.context.junit4.SpringJUnit4ClassRunner$1.runReflectiveCall(SpringJUnit4ClassRunner.java:289)
at
org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at
org.springframework.test.context.junit4.SpringJUnit4ClassRunner.methodBlock(SpringJUnit4ClassRunner.java:291)
at
org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:246)
at
org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:97)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at
org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
at
org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at
org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:190)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at
com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:69)
at
com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:33)
at
com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:220)
at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:53)
Caused by: org.springframework.beans.factory.BeanCreationException: Error
creating bean with name
'org.apache.shardingsphere.spring.boot.ShardingSphereAutoConfiguration':
Initialization of bean failed; nested exception is
org.apache.shardingsphere.infra.exception.ShardingSphereException: Can't find
data source type.
at
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.GeneratedMethodAccessor72.invoke(Unknown Source)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at
org.apache.shardingsphere.spring.boot.util.PropertyUtil.v2(PropertyUtil.java:111)
at
org.apache.shardingsphere.spring.boot.util.PropertyUtil.handle(PropertyUtil.java:75)
at
org.apache.shardingsphere.spring.boot.datasource.DataSourceMapSetter.getDataSource(DataSourceMapSetter.java:87)
at
org.apache.shardingsphere.spring.boot.datasource.DataSourceMapSetter.getDataSourceMap(DataSourceMapSetter.java:65)
... 53 more
Caused by: java.util.NoSuchElementException: No value bound
at
org.springframework.boot.context.properties.bind.BindResult.get(BindResult.java:56)
... 60 more
### Example codes for reproduce this issue (such as a github link).
nacos ym file:
server:
port: 22001
spring:
shardingsphere:
datasource:
names: write-ds-0,write-ds-1,read-ds-0,read-ds-1
write-ds-0:
jdbc-url:
jdbc:mysql://172.17.30.208:3306/write_ds_0?serverTimezone=UTC&useSSL=false&useUnicode=true&characterEncoding=UTF-8
type: com.zaxxer.hikari.HikariDataSource
driver-class-name: com.mysql.cj.jdbc.Driver
username: root
password: 123456!
max-active: 16
read-ds-0:
jdbc-url:
jdbc:mysql://172.17.30.208:3306/read_ds_0?serverTimezone=UTC&useSSL=false&useUnicode=true&characterEncoding=UTF-8
type: com.zaxxer.hikari.HikariDataSource
driver-class-name: com.mysql.cj.jdbc.Driver
username: root
password: 123456!
max-active: 16
write-ds-1:
jdbc-url:
jdbc:mysql://172.17.30.208:3306/write_ds_1?serverTimezone=UTC&useSSL=false&useUnicode=true&characterEncoding=UTF-8
type: com.zaxxer.hikari.HikariDataSource
driver-class-name: com.mysql.cj.jdbc.Driver
username: root
password: 123456!
max-active: 16
write-ds-1-read-0:
jdbc-url:
jdbc:mysql://172.17.30.208:3306/read_ds_1?serverTimezone=UTC&useSSL=false&useUnicode=true&characterEncoding=UTF-8
type: com.zaxxer.hikari.HikariDataSource
driver-class-name: com.mysql.cj.jdbc.Driver
username: root
password: 123456!
max-active: 16
rules:
sharding:
default-database-strategy:
standard:
sharding-column: user_id
sharding-algorithm-name: database-inline
binding-tables[0]: t_order,t_order_item
broadcast-tables: t_address
tables:
t_order:
actual-data-nodes: write-ds-$->{0..1}.t_order_$->{0..1}
table-strategy:
standard:
sharding-column: order_id
sharding-algorithm-name: t-order-inline
key-generate-strategy:
column: order_id
key-generator-name: snowflake
t_order_item:
actual-data-nodes: write-ds-$->{0..1}.t_order_item_$->{0..1}
table-strategy:
standard:
sharding-column: order_id
sharding-algorithm-name: t-order-item-inline
key-generate-strategy:
column: order_item_id
key-generator-name: snowflake
key-generators:
snowflake:
type: SNOWFLAKE
props:
worker-id: 123
sharding-algorithms:
database-inline:
type: INLINE
props:
algorithm-expression: write-ds-$->{user_id % 2}
t-order-inline:
type: INLINE
props:
algorithm-expression: t_order_$->{order_id % 2}
t-order-item-inline:
type: INLINE
props:
algorithm-expression: t_order_item_$->{order_id % 2}
readwrite-splitting:
data-sources:
ds-0:
write-data-source-name: write-ds-0
read-data-source-names: read-ds-0
ds-1:
write-data-source-name: write-ds-1
read-data-source-names: read-ds-1
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class})
@EnableDiscoveryClient
@EnableFeignClients
@MapperScan("com.test.**.dao")
@ComponentScan({"com.test"})
public class ShardingSeataApplication {
public static void main(String[] args) {
SpringApplication.run(ShardingSeataApplication.class, args);
}
}
--
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]