xtuer opened a new issue #8435: URL: https://github.com/apache/shardingsphere/issues/8435
## Question When loading configuration from Zookeeper follow the [orchestration doc](https://shardingsphere.apache.org/document/legacy/4.x/document/cn/manual/sharding-jdbc/configuration/config-yaml/#%E6%B2%BB%E7%90%86). It throws error like: Factory method 'dataSource' threw exception; nested exception is Cannot create property=orchestration for JavaBean=org.apache.shardingsphere.shardingjdbc.orchestration.internal.yaml.YamlOrchestrationShardingRuleConfiguration@3aefae67 in 'reader', line 2, column 1: orchestration: ^ No single argument constructor found for class org.apache.shardingsphere.orchestration.center.yaml.config.YamlCenterRepositoryConfiguration : null Environment: JDK: Java 8 Zookeeper 3.6.1 Sharding-JDBC 4.1.1 ## What I did as follow: 1. import dependencies in build.gradle ``` dependencies { implementation ( 'org.springframework.boot:spring-boot-starter-web', 'org.mybatis.spring.boot:mybatis-spring-boot-starter:2.1.1', 'org.apache.shardingsphere:sharding-jdbc-core:4.1.1', 'org.apache.shardingsphere:sharding-jdbc-orchestration:4.1.1', ) implementation('org.apache.shardingsphere:sharding-orchestration-center-zookeeper-curator:4.1.1') { exclude group: 'org.apache.curator', module: 'curator-framework' exclude group: 'org.apache.curator', module: 'curator-recipes' exclude group: 'org.apache.curator', module: 'curator-client' } implementation( 'org.apache.curator:curator-framework:3.3.0', 'org.apache.curator:curator-recipes:3.3.0', ) runtimeOnly('mysql:mysql-connector-java:5.1.46') testImplementation 'org.springframework.boot:spring-boot-starter-test' } ``` 2. Sharding-JDBC yaml configuration ``` orchestration: name: orchestration-sharding-data-source overwrite: true registry: type: zookeeper serverLists: localhost:2181 namespace: sharding-sphere-orchestration dataSources: ds0: !!com.zaxxer.hikari.HikariDataSource driverClassName: com.mysql.jdbc.Driver jdbcUrl: jdbc:mysql://localhost:3306/demo_ds_0 username: root password: root ds1: !!com.zaxxer.hikari.HikariDataSource driverClassName: com.mysql.jdbc.Driver jdbcUrl: jdbc:mysql://localhost:3306/demo_ds_1 username: root password: root shardingRule: tables: user: actualDataNodes: ds${0..1}.user databaseStrategy: inline: shardingColumn: user_id algorithmExpression: ds${user_id % 2} defaultTableStrategy: none: ``` 3. Create DataSource Using Java Code ```java @Configuration public class AppConfig { @Bean public DataSource dataSource() throws IOException, SQLException { File yamlCfg = new File(new ClassPathResource("sharding-jdbc.yml").getURI()); DataSource dataSource = YamlOrchestrationShardingDataSourceFactory.createDataSource(yamlCfg); return dataSource; } } ``` ---------------------------------------------------------------- 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. For queries about this service, please contact Infrastructure at: [email protected]
