apache / shardingsphere

Distributed SQL transaction & query engine for data sharding, scaling, encryption, and more - on any database.
Apache License 2.0
19.61k stars 6.66k forks source link

Configure the yaml file as per the official documentation, but it keeps reporting errors #23796

Closed 790477691 closed 4 months ago

790477691 commented 1 year ago
Exception in thread "main" Cannot create property=mode for JavaBean=org.apache.shardingsphere.infra.yaml.config.pojo.YamlRootConfiguration@1700915
 in 'reader', line 1, column 1:
    databaseName: oracleSource
    ^
No single argument constructor found for class org.apache.shardingsphere.infra.yaml.config.pojo.mode.YamlModeConfiguration
 in 'reader', line 2, column 7:
    mode: standalone
          ^

    at org.yaml.snakeyaml.constructor.Constructor$ConstructMapping.constructJavaBean2ndStep(Constructor.java:321)
    at org.yaml.snakeyaml.constructor.Constructor$ConstructMapping.construct(Constructor.java:207)
    at org.yaml.snakeyaml.constructor.Constructor$ConstructYamlObject.construct(Constructor.java:358)
    at org.yaml.snakeyaml.constructor.BaseConstructor.constructObjectNoCheck(BaseConstructor.java:270)
    at org.yaml.snakeyaml.constructor.BaseConstructor.constructObject(BaseConstructor.java:253)
    at org.yaml.snakeyaml.constructor.BaseConstructor.constructDocument(BaseConstructor.java:207)
    at org.yaml.snakeyaml.constructor.BaseConstructor.getSingleData(BaseConstructor.java:191)
    at org.yaml.snakeyaml.Yaml.loadFromReader(Yaml.java:477)
    at org.yaml.snakeyaml.Yaml.loadAs(Yaml.java:443)
    at org.apache.shardingsphere.infra.util.yaml.YamlEngine.unmarshal(YamlEngine.java:55)
    at org.apache.shardingsphere.driver.api.yaml.YamlShardingSphereDataSourceFactory.createDataSource(YamlShardingSphereDataSourceFactory.java:61)
    at Test.main(Test.java:30)
Caused by: org.yaml.snakeyaml.error.YAMLException: No single argument constructor found for class org.apache.shardingsphere.infra.yaml.config.pojo.mode.YamlModeConfiguration
    at org.yaml.snakeyaml.constructor.Constructor$ConstructScalar.construct(Constructor.java:417)
    at org.yaml.snakeyaml.constructor.BaseConstructor.constructObjectNoCheck(BaseConstructor.java:270)
    at org.yaml.snakeyaml.constructor.BaseConstructor.constructObject(BaseConstructor.java:253)
    at org.yaml.snakeyaml.constructor.Constructor$ConstructMapping.newInstance(Constructor.java:333)
    at org.yaml.snakeyaml.constructor.Constructor$ConstructMapping.constructJavaBean2ndStep(Constructor.java:298)
    ... 11 more

pom

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.lxz.shardingjdbcspring</groupId>
    <artifactId>shardingjdbcspring</artifactId>
    <version>1.0-SNAPSHOT</version>

    <dependencies>
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>druid</artifactId>
            <version>1.1.20</version>
        </dependency>
        <dependency>
            <groupId>com.oracle.database.nls</groupId>
            <artifactId>orai18n</artifactId>
            <version>11.2.0.4</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.apache.shardingsphere/shardingsphere-jdbc-core -->
        <dependency>
            <groupId>org.apache.shardingsphere</groupId>
            <artifactId>shardingsphere-jdbc-core</artifactId>
            <version>5.3.1</version>
        </dependency>
        <dependency>
            <groupId>cn.easyproject</groupId>
            <artifactId>ojdbc6</artifactId>
            <version>12.1.0.2.0</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-test</artifactId>
            <version>5.0.4.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context-support</artifactId>
            <version>5.0.4.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-tx</artifactId>
            <version>5.0.4.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
            <version>5.0.4.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-jdbc</artifactId>
            <version>5.0.4.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.mybatis</groupId>
            <artifactId>mybatis-spring</artifactId>
            <version>1.3.0</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/junit/junit -->
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.13.2</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>1.7.7</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
            <version>1.7.7</version>
        </dependency>
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.17</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-slf4j-impl -->
        <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-slf4j-impl</artifactId>
            <version>2.19.0</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.35</version>
        </dependency>
    </dependencies>

    <build>
        <finalName>mjm-web-server</finalName>
        <resources>
            <resource>
                <directory>src/main/resource</directory>
                <includes>
                    <include>**/*</include>
                </includes>
            </resource>
            <resource>
                <directory>src/main/resource</directory>
                <includes>
                    <include>log4j.properties</include>
                    <include>db.properties</include>
                </includes>
                <filtering>true</filtering>
            </resource>
        </resources>

        <plugins>
            <!-- jdk版本1.8 -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                    <encoding>utf-8</encoding>
                </configuration>
            </plugin>

            <!--打包跳过测试类-->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <configuration>
                    <testFailureIgnore>true</testFailureIgnore>
                    <skip>true</skip>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <executions>
                    <execution>
                        <id>copy-installed</id>
                        <phase>package</phase>
                        <goals>
                            <goal>copy</goal>
                        </goals>
                        <configuration>
                            <artifactItems>
                                <artifactItem>
                                    <groupId>${project.groupId}</groupId>
                                    <artifactId>${project.artifactId}</artifactId>
                                    <version>${project.version}</version>
                                    <type>${project.packaging}</type>
                                </artifactItem>
                            </artifactItems>
                            <outputDirectory>target/lib</outputDirectory>
                        </configuration>
                    </execution>
                    <execution>
                        <id>copy-lib</id>
                        <phase>prepare-package</phase>
                        <goals>
                            <goal>copy-dependencies</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${project.build.directory}/lib</outputDirectory>
                            <overWriteReleases>false</overWriteReleases>
                            <overWriteSnapshots>false</overWriteSnapshots>
                            <overWriteIfNewer>true</overWriteIfNewer>
                            <includeScope>compile</includeScope>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

scratch.yaml

databaseName: oracleSource
mode: standalone
dataSources:
  oracleSource1:
    dataSourceClassName: com.alibaba.druid.pool.DruidDataSource
    driverClassName: oracle.jdbc.driver.OracleDriver
    jdbcUrl: jdbc:oracle:thin:@***:***:road
    username: 111
    password: 1111
    connectionTimeoutMilliseconds: 30000
    idleTimeoutMilliseconds: 60000
    maxLifetimeMilliseconds: 1800000
    maxPoolSize: 50
    minPoolSize: 1
  oracleSource2:
    dataSourceClassName: com.alibaba.druid.pool.DruidDataSource
    driverClassName: oracle.jdbc.driver.OracleDriver
    jdbcUrl: jdbc:oracle:thin:@***:***:road1
    username: 111
    password: 111
    connectionTimeoutMilliseconds: 30000
    idleTimeoutMilliseconds: 60000
    maxLifetimeMilliseconds: 1800000
    maxPoolSize: 50
    minPoolSize: 1
  oracleSource3:
    dataSourceClassName: com.alibaba.druid.pool.DruidDataSource
    driverClassName: oracle.jdbc.driver.OracleDriver
    jdbcUrl: jdbc:oracle:thin:@***:***:road2
    username: 111
    password: 111
    connectionTimeoutMilliseconds: 30000
    idleTimeoutMilliseconds: 60000
    maxLifetimeMilliseconds: 1800000
    maxPoolSize: 50
    minPoolSize: 1

rules:
    tables:
      MJM_GPS_RECORD:
        actualDataNodes: oracleSource${1..3}.MJM_GPS_RECORD
        databaseStrategy:
          standard:
            shardingColumn: TELEPHONE
            shardingAlgorithmName: hint_test
      MJM_JS_ATTACHMENT:
        actualDataNodes: oracleSource${1..3}.MJM_JS_ATTACHMENT
        databaseStrategy:
          standard:
            shardingColumn: SIM_NUMBER
            shardingAlgorithmName: hint_test
      MJM_JS_BLIND_AREA:
        actualDataNodes: oracleSource${1..3}.MJM_JS_BLIND_AREA
        databaseStrategy:
          standard:
            shardingColumn: SIM_NUMBER
            shardingAlgorithmName: hint_test
      MJM_JS_DRIVER_STATUS:
        actualDataNodes: oracleSource${1..3}.MJM_JS_DRIVER_STATUS
        databaseStrategy:
          standard:
            shardingColumn: SIM_NUMBER
            shardingAlgorithmName: hint_test
      MJM_JS_DRIVING_ASS:
        actualDataNodes: oracleSource${1..3}.MJM_JS_DRIVING_ASS
        databaseStrategy:
          standard:
            shardingColumn: SIM_NUMBER
            shardingAlgorithmName: hint_test
      MJM_WARNING:
        actualDataNodes: oracleSource${1..3}.MJM_WARNING
        databaseStrategy:
          standard:
            shardingColumn: SIM_NUMBER
            shardingAlgorithmName: hint_test
    bindingTables: MJM_GPS_RECORD,MJM_JS_ATTACHMENT,MJM_JS_BLIND_AREA,MJM_JS_DRIVER_STATUS,MJM_JS_DRIVING_ASS,MJM_WARNING
    broadcastTables: MJM_REPORT_LAST_POSITION,MJM_8702,T_SERVER_DB,T_GPS_RECORD_LOG_JOB,MJM_PICTURE_MATCH

    #    defaultDatabaseStrategy:
    #      hint:
    #        shardingColumn:
    #        shardingAlgorithmName: hint_test
    #    defaultTableStrategy:
    #      none:

    shardingAlgorithms:
      hint_test:
        type: HINT_TEST
props:
  max-connections-size-per-query: 1
  kernel-executor-size: 16  # Infinite by default.
  proxy-frontend-flush-threshold: 128  # The default value is 128.
  proxy-hint-enabled: true
  sql-show: true
  check-table-metadata-enabled: false

spring-datasource.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:sharding="http://shardingsphere.apache.org/schema/shardingsphere/sharding"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
       http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
       http://www.springframework.org/schema/context
       http://www.springframework.org/schema/context/spring-context.xsd
       http://www.springframework.org/schema/jdbc
       http://www.springframework.org/schema/jdbc/spring-jdbc.xsd
       http://shardingsphere.apache.org/schema/shardingsphere/sharding
       http://shardingsphere.apache.org/schema/shardingsphere/sharding/sharding.xsd">

    <context:property-placeholder location="classpath:db.properties" ignore-unresolvable="true"/>

    <bean id="stat-filter" class="com.alibaba.druid.filter.stat.StatFilter">
        <property name="slowSqlMillis" value="2000"/>
        <property name="logSlowSql" value="true"/>
    </bean>

    <bean id="dataSource" class="DynamicDataSource" >
        <property name="targetDataSources">
            <map>
                <entry key="mysqlSource" value-ref="mysqlSource"/>
                <entry key="mysqlSourceBj" value-ref="mysqlSourceBj"/>
                <entry key="oracleSource" value-ref="oracleSource"/>
<!--                <entry key="oracleSource" value-ref="shardingDataSource"/>-->
<!--                <entry key="h2Source" value-ref="h2Source" />-->
            </map>
        </property>
        <property name="defaultTargetDataSource" ref="mysqlSource"/>
    </bean>

    <bean id="parentSource" class="com.alibaba.druid.pool.DruidDataSource">
        <!-- 配置获取连接等待超时的时间 -->
        <property name="maxWait" value="${jdbc.maxWait}"/>
        <!-- 初始大小 -->
        <property name="initialSize" value="${jdbc.initialSize}"/>
        <!-- 最小个数 -->
        <property name="minIdle" value="${jdbc.minIdle}"/>
        <!-- 最大个数 -->
        <property name="maxActive" value="${jdbc.maxActive}"/>

        <!-- 打开PSCache,并且指定每个连接上PSCache的大小 -->
        <!--  如果用Oracle,则把poolPreparedStatements配置为true,mysql可以配置为false。分库分表较多的数据库,建议配置为false。-->
        <property name="poolPreparedStatements" value="false"/>
        <property name="maxPoolPreparedStatementPerConnectionSize" value="20"/>

        <property name="filters" value="${jdbc.filters}"/>
        <property name="timeBetweenEvictionRunsMillis" value="${jdbc.timeBetweenEvictionRunsMillis}"/>
        <property name="minEvictableIdleTimeMillis" value="${jdbc.minEvictableIdleTimeMillis}"/>
        <property name="testWhileIdle" value="${jdbc.testWhileIdle}"/>
        <property name="testOnBorrow" value="${jdbc.testOnBorrow}"/>
        <property name="testOnReturn" value="${jdbc.testOnReturn}"/>

        <!-- 启用监控 -->
        <property name="proxyFilters">
            <list>
                <ref bean="stat-filter"/>
            </list>
        </property>
        <property name="connectionProperties">
            <value>${jdbc.connproperty}</value>
        </property>
    </bean>

    <bean id="mysqlSource" parent="parentSource" init-method="init" destroy-method="close">
        <property name="driverClassName" value="${jdbc.driverClassName}"/>
        <property name="url" value="${jdbc.url}"/>
        <property name="username" value="${jdbc.username}"/>
        <property name="password" value="${jdbc.password}"/>
        <property name="validationQuery" value="select 1"/>
    </bean>
    <bean id="mysqlSourceBj" parent="parentSource" init-method="init" destroy-method="close">
        <property name="driverClassName" value="${jdbc.driverClassName1}"/>
        <property name="url" value="${jdbc.url1}"/>
        <property name="username" value="${jdbc.username1}"/>
        <property name="password" value="${jdbc.password1}"/>
        <property name="validationQuery" value="select 1"/>
    </bean>
    <bean id="oracleSource" parent="parentSource" init-method="init" destroy-method="close">
        <property name="driverClassName" value="org.apache.shardingsphere.driver.ShardingSphereDriver"/>
        <property name="url" value="jdbc:shardingsphere:classpath:scratch.yaml" />
    </bean>

</beans>

DynamicDataSource

import com.alibaba.druid.pool.DruidDataSource;
import com.alibaba.druid.pool.DruidPooledConnection;
import org.springframework.core.annotation.Order;
import org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource;

import java.sql.SQLException;
import java.util.logging.Logger;

@Order(2)
public class DynamicDataSource extends AbstractRoutingDataSource  {

    /**
     * 取得当前使用那个数据源。
     */
    @Override
    protected Object determineCurrentLookupKey() {
        return DataSourceContextHolder.getDbType();
    }

    public Logger getParentLogger() {
        // TODO Auto-generated method stub
        return null;
    }

}

DataSourceContextHolder


public class DataSourceContextHolder {

    /**
     * 默认数据源
     */
    public static final String DEFAULT_DS = DataSourceConst.MYSQL_SOURCE;

    /**
     * 数据源标识保存在线程变量中,避免多线程操作数据源时互相干扰
     */
    private static final ThreadLocal<String> contextHolder = new ThreadLocal<String>();

    /**
     * 设置当前数据库。
     * @param dbType
     */
    public static void setDbType(String dbType)
    {
        contextHolder.set(dbType);
    }

    /**
     * 取得当前数据源。
     * @return
     */
    public static String getDbType() {
        if (contextHolder.get() == null){
            return DEFAULT_DS;
        }else {
            return (String) contextHolder.get();
        }
    }

    /**
     * 清除上下文数据
     */
    public static void clearDbType()
    {
        contextHolder.remove();
    }
}
RaigorJiang commented 1 year ago

@790477691 It may be that the version of snakeyaml that springframework depends on is too low, please try to specify the version of snakeyaml in the pom

<dependency>
     <groupId>org.yaml</groupId>
     <artifactId>snakeyaml</artifactId>
     <version>1.33</version>
</dependency>
790477691 commented 1 year ago

I replaced it with this configuration, but it still doesn't work

        <!-- https://mvnrepository.com/artifact/org.apache.shardingsphere/shardingsphere-jdbc-core -->
        <dependency>
            <groupId>org.apache.shardingsphere</groupId>
            <artifactId>shardingsphere-jdbc-core</artifactId>
            <version>5.2.1</version>
            <exclusions>
                <exclusion>
                    <groupId>org.yaml</groupId>
                    <artifactId>snakeyaml</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.yaml/snakeyaml -->
        <dependency>
            <groupId>org.yaml</groupId>
            <artifactId>snakeyaml</artifactId>
            <version>1.33</version>
        </dependency>
[INFO] -----------< com.lxz.shardingjdbcspring:shardingjdbcspring >------------
[INFO] Building shardingjdbcspring 1.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) @ shardingjdbcspring ---
[INFO] com.lxz.shardingjdbcspring:shardingjdbcspring:jar:1.0-SNAPSHOT
[INFO] +- com.alibaba:druid:jar:1.1.20:compile
[INFO] +- com.oracle.database.nls:orai18n:jar:11.2.0.4:compile
[INFO] +- org.apache.shardingsphere:shardingsphere-jdbc-core:jar:5.2.1:compile
[INFO] |  +- org.apache.shardingsphere:shardingsphere-transaction-core:jar:5.2.1:compile
[INFO] |  |  +- org.apache.shardingsphere:shardingsphere-transaction-api:jar:5.2.1:compile
[INFO] |  |  \- org.apache.shardingsphere:shardingsphere-infra-executor:jar:5.2.1:compile
[INFO] |  |     \- io.vertx:vertx-mysql-client:jar:4.3.3:compile
[INFO] |  |        +- io.vertx:vertx-core:jar:4.3.3:compile
[INFO] |  |        |  +- io.netty:netty-common:jar:4.1.78.Final:compile
[INFO] |  |        |  +- io.netty:netty-buffer:jar:4.1.78.Final:compile
[INFO] |  |        |  +- io.netty:netty-transport:jar:4.1.78.Final:compile
[INFO] |  |        |  +- io.netty:netty-handler:jar:4.1.78.Final:compile
[INFO] |  |        |  |  +- io.netty:netty-transport-native-unix-common:jar:4.1.78.Final:compile
[INFO] |  |        |  |  \- io.netty:netty-codec:jar:4.1.78.Final:compile
[INFO] |  |        |  +- io.netty:netty-handler-proxy:jar:4.1.78.Final:compile
[INFO] |  |        |  |  \- io.netty:netty-codec-socks:jar:4.1.78.Final:compile
[INFO] |  |        |  +- io.netty:netty-codec-http:jar:4.1.78.Final:compile
[INFO] |  |        |  +- io.netty:netty-codec-http2:jar:4.1.78.Final:compile
[INFO] |  |        |  +- io.netty:netty-resolver:jar:4.1.78.Final:compile
[INFO] |  |        |  +- io.netty:netty-resolver-dns:jar:4.1.78.Final:compile
[INFO] |  |        |  |  \- io.netty:netty-codec-dns:jar:4.1.78.Final:compile
[INFO] |  |        |  \- com.fasterxml.jackson.core:jackson-core:jar:2.13.2:compile
[INFO] |  |        \- io.vertx:vertx-sql-client:jar:4.3.3:compile
[INFO] |  +- org.apache.shardingsphere:shardingsphere-sql-parser-sql92:jar:5.2.1:compile
[INFO] |  |  \- org.apache.shardingsphere:shardingsphere-sql-parser-engine:jar:5.2.1:compile
[INFO] |  |     +- org.apache.shardingsphere:shardingsphere-sql-parser-spi:jar:5.2.1:compile
[INFO] |  |     +- org.apache.shardingsphere:shardingsphere-sql-parser-statement:jar:5.2.1:compile
[INFO] |  |     +- org.antlr:antlr4-runtime:jar:4.9.2:compile
[INFO] |  |     \- com.github.ben-manes.caffeine:caffeine:jar:2.9.2:compile
[INFO] |  +- org.apache.shardingsphere:shardingsphere-sql-parser-mysql:jar:5.2.1:compile
[INFO] |  +- org.apache.shardingsphere:shardingsphere-sql-parser-postgresql:jar:5.2.1:compile
[INFO] |  +- org.apache.shardingsphere:shardingsphere-sql-parser-oracle:jar:5.2.1:compile
[INFO] |  +- org.apache.shardingsphere:shardingsphere-sql-parser-sqlserver:jar:5.2.1:compile
[INFO] |  +- org.apache.shardingsphere:shardingsphere-sql-parser-opengauss:jar:5.2.1:compile
[INFO] |  +- org.apache.shardingsphere:shardingsphere-mysql-dialect-exception:jar:5.2.1:compile
[INFO] |  |  \- org.apache.shardingsphere:shardingsphere-dialect-exception-core:jar:5.2.1:compile
[INFO] |  +- org.apache.shardingsphere:shardingsphere-postgresql-dialect-exception:jar:5.2.1:compile
[INFO] |  +- org.apache.shardingsphere:shardingsphere-authority-core:jar:5.2.1:compile
[INFO] |  |  \- org.apache.shardingsphere:shardingsphere-authority-api:jar:5.2.1:compile
[INFO] |  +- org.apache.shardingsphere:shardingsphere-single-table-core:jar:5.2.1:compile
[INFO] |  |  +- org.apache.shardingsphere:shardingsphere-single-table-api:jar:5.2.1:compile
[INFO] |  |  \- org.apache.shardingsphere:shardingsphere-infra-route:jar:5.2.1:compile
[INFO] |  +- org.apache.shardingsphere:shardingsphere-traffic-core:jar:5.2.1:compile
[INFO] |  |  +- org.apache.shardingsphere:shardingsphere-infra-common:jar:5.2.1:compile
[INFO] |  |  |  \- org.apache.shardingsphere:shardingsphere-infra-util:jar:5.2.1:compile
[INFO] |  |  |     \- org.apache.groovy:groovy:jar:4.0.3:compile
[INFO] |  |  +- org.apache.shardingsphere:shardingsphere-infra-binder:jar:5.2.1:compile
[INFO] |  |  \- org.apache.shardingsphere:shardingsphere-traffic-api:jar:5.2.1:compile
[INFO] |  +- org.apache.shardingsphere:shardingsphere-infra-context:jar:5.2.1:compile
[INFO] |  |  +- org.apache.shardingsphere:shardingsphere-distsql-parser:jar:5.2.1:compile
[INFO] |  |  |  \- org.apache.shardingsphere:shardingsphere-distsql-statement:jar:5.2.1:compile
[INFO] |  |  \- org.apache.shardingsphere:shardingsphere-sql-translator-core:jar:5.2.1:compile
[INFO] |  |     \- org.apache.shardingsphere:shardingsphere-sql-translator-api:jar:5.2.1:compile
[INFO] |  +- org.apache.shardingsphere:shardingsphere-standalone-mode-core:jar:5.2.1:compile
[INFO] |  |  +- org.apache.shardingsphere:shardingsphere-mode-core:jar:5.2.1:compile
[INFO] |  |  \- org.apache.shardingsphere:shardingsphere-standalone-mode-repository-api:jar:5.2.1:compile
[INFO] |  +- org.apache.shardingsphere:shardingsphere-standalone-mode-repository-jdbc-h2:jar:5.2.1:compile
[INFO] |  |  \- org.apache.shardingsphere:shardingsphere-standalone-mode-repository-jdbc-core:jar:5.2.1:compile
[INFO] |  |     \- com.zaxxer:HikariCP:jar:3.4.2:compile
[INFO] |  +- org.apache.shardingsphere:shardingsphere-cluster-mode-core:jar:5.2.1:compile
[INFO] |  |  \- org.apache.shardingsphere:shardingsphere-cluster-mode-repository-api:jar:5.2.1:compile
[INFO] |  +- org.apache.shardingsphere:shardingsphere-sharding-core:jar:5.2.1:compile
[INFO] |  |  +- org.apache.shardingsphere:shardingsphere-sharding-api:jar:5.2.1:compile
[INFO] |  |  +- org.apache.shardingsphere:shardingsphere-data-pipeline-core:jar:5.2.1:compile
[INFO] |  |  |  +- org.apache.shardingsphere:shardingsphere-data-pipeline-api:jar:5.2.1:compile
[INFO] |  |  |  |  \- org.apache.commons:commons-lang3:jar:3.8:compile
[INFO] |  |  |  \- org.apache.shardingsphere:shardingsphere-cluster-mode-repository-zookeeper-curator:jar:5.2.1:compile
[INFO] |  |  |     +- org.apache.curator:curator-framework:jar:5.1.0:compile
[INFO] |  |  |     +- org.apache.curator:curator-client:jar:5.1.0:compile
[INFO] |  |  |     |  \- org.apache.zookeeper:zookeeper:jar:3.6.0:compile
[INFO] |  |  |     |     +- commons-lang:commons-lang:jar:2.6:compile
[INFO] |  |  |     |     +- org.apache.zookeeper:zookeeper-jute:jar:3.6.0:compile
[INFO] |  |  |     |     +- org.apache.yetus:audience-annotations:jar:0.5.0:compile
[INFO] |  |  |     |     \- io.netty:netty-transport-native-epoll:jar:4.1.45.Final:compile
[INFO] |  |  |     \- org.apache.curator:curator-recipes:jar:5.1.0:compile
[INFO] |  |  +- org.apache.shardingsphere:shardingsphere-infra-rewrite:jar:5.2.1:compile
[INFO] |  |  |  \- org.apache.shardingsphere:shardingsphere-sql-translator-native-provider:jar:5.2.1:compile
[INFO] |  |  +- org.apache.shardingsphere:shardingsphere-infra-merge:jar:5.2.1:compile
[INFO] |  |  |  \- org.apache.calcite:calcite-linq4j:jar:1.32.0:compile
[INFO] |  |  |     +- org.apiguardian:apiguardian-api:jar:1.1.2:compile
[INFO] |  |  |     \- org.apache.calcite.avatica:avatica-core:jar:1.22.0:compile
[INFO] |  |  |        +- org.apache.calcite.avatica:avatica-metrics:jar:1.22.0:compile
[INFO] |  |  |        +- com.fasterxml.jackson.core:jackson-annotations:jar:2.10.0:compile
[INFO] |  |  |        +- com.fasterxml.jackson.core:jackson-databind:jar:2.10.0:compile
[INFO] |  |  |        +- com.google.protobuf:protobuf-java:jar:3.17.1:compile
[INFO] |  |  |        +- org.apache.httpcomponents.client5:httpclient5:jar:5.1.3:runtime
[INFO] |  |  |        |  \- org.apache.httpcomponents.core5:httpcore5-h2:jar:5.1.3:runtime
[INFO] |  |  |        \- org.apache.httpcomponents.core5:httpcore5:jar:5.1.3:runtime
[INFO] |  |  +- org.apache.shardingsphere:shardingsphere-system-datetime:jar:5.2.1:compile
[INFO] |  |  |  \- org.apache.shardingsphere:shardingsphere-infra-datetime-spi:jar:5.2.1:compile
[INFO] |  |  +- org.apache.shardingsphere:shardingsphere-sharding-cosid:jar:5.2.1:compile
[INFO] |  |  |  \- me.ahoo.cosid:cosid-core:jar:1.14.4:compile
[INFO] |  |  \- org.apache.shardingsphere:shardingsphere-sharding-nanoid:jar:5.2.1:compile
[INFO] |  |     \- com.aventrix.jnanoid:jnanoid:jar:2.0.0:compile
[INFO] |  +- org.apache.shardingsphere:shardingsphere-sharding-cache:jar:5.2.1:compile
[INFO] |  +- org.apache.shardingsphere:shardingsphere-readwrite-splitting-core:jar:5.2.1:compile
[INFO] |  |  \- org.apache.shardingsphere:shardingsphere-readwrite-splitting-api:jar:5.2.1:compile
[INFO] |  +- org.apache.shardingsphere:shardingsphere-db-discovery-core:jar:5.2.1:compile
[INFO] |  |  +- org.apache.shardingsphere:shardingsphere-db-discovery-api:jar:5.2.1:compile
[INFO] |  |  +- org.apache.shardingsphere:shardingsphere-db-discovery-mysql:jar:5.2.1:compile
[INFO] |  |  +- org.apache.shardingsphere:shardingsphere-db-discovery-opengauss:jar:5.2.1:compile
[INFO] |  |  \- org.apache.shardingsphere:shardingsphere-schedule-core:jar:5.2.1:compile
[INFO] |  |     +- org.apache.shardingsphere.elasticjob:elasticjob-lite-core:jar:3.0.1:compile
[INFO] |  |     |  +- org.apache.shardingsphere.elasticjob:elasticjob-api:jar:3.0.1:compile
[INFO] |  |     |  +- org.apache.shardingsphere.elasticjob:elasticjob-infra-common:jar:3.0.1:compile
[INFO] |  |     |  +- org.apache.shardingsphere.elasticjob:elasticjob-registry-center:jar:3.0.1:compile
[INFO] |  |     |  +- org.apache.shardingsphere.elasticjob:elasticjob-simple-executor:jar:3.0.1:compile
[INFO] |  |     |  |  \- org.apache.shardingsphere.elasticjob:elasticjob-executor-kernel:jar:3.0.1:compile
[INFO] |  |     |  |     \- org.apache.shardingsphere.elasticjob:elasticjob-error-handler-general:jar:3.0.1:compile
[INFO] |  |     |  |        \- org.apache.shardingsphere.elasticjob:elasticjob-error-handler-spi:jar:3.0.1:compile
[INFO] |  |     |  +- org.apache.shardingsphere.elasticjob:elasticjob-dataflow-executor:jar:3.0.1:compile
[INFO] |  |     |  +- org.apache.shardingsphere.elasticjob:elasticjob-script-executor:jar:3.0.1:compile
[INFO] |  |     |  |  \- org.apache.commons:commons-exec:jar:1.3:compile
[INFO] |  |     |  +- org.apache.shardingsphere.elasticjob:elasticjob-http-executor:jar:3.0.1:compile
[INFO] |  |     |  +- org.apache.shardingsphere.elasticjob:elasticjob-tracing-rdb:jar:3.0.1:compile
[INFO] |  |     |  |  \- org.apache.shardingsphere.elasticjob:elasticjob-tracing-api:jar:3.0.1:compile
[INFO] |  |     |  +- com.google.code.gson:gson:jar:2.6.1:compile
[INFO] |  |     |  \- org.quartz-scheduler:quartz:jar:2.3.2:compile
[INFO] |  |     |     \- com.mchange:mchange-commons-java:jar:0.2.15:compile
[INFO] |  |     \- org.apache.shardingsphere.elasticjob:elasticjob-lite-lifecycle:jar:3.0.1:compile
[INFO] |  +- org.apache.shardingsphere:shardingsphere-encrypt-core:jar:5.2.1:compile
[INFO] |  |  +- org.apache.shardingsphere:shardingsphere-encrypt-api:jar:5.2.1:compile
[INFO] |  |  +- org.apache.shardingsphere:shardingsphere-encrypt-sm:jar:5.2.1:compile
[INFO] |  |  |  \- org.bouncycastle:bcprov-jdk15on:jar:1.70:compile
[INFO] |  |  \- commons-codec:commons-codec:jar:1.15:compile
[INFO] |  +- org.apache.shardingsphere:shardingsphere-shadow-core:jar:5.2.1:compile
[INFO] |  |  \- org.apache.shardingsphere:shardingsphere-shadow-api:jar:5.2.1:compile
[INFO] |  +- org.apache.shardingsphere:shardingsphere-sql-federation-core:jar:5.2.1:compile
[INFO] |  |  \- org.apache.shardingsphere:shardingsphere-sql-federation-api:jar:5.2.1:compile
[INFO] |  +- org.apache.shardingsphere:shardingsphere-sql-federation-executor-advanced:jar:5.2.1:compile
[INFO] |  |  \- org.apache.shardingsphere:shardingsphere-sql-federation-executor-core:jar:5.2.1:compile
[INFO] |  |     \- org.apache.shardingsphere:shardingsphere-sql-federation-optimizer:jar:5.2.1:compile
[INFO] |  |        \- org.apache.calcite:calcite-core:jar:1.32.0:compile
[INFO] |  |           +- org.locationtech.jts:jts-core:jar:1.19.0:compile
[INFO] |  |           +- org.locationtech.jts.io:jts-io-common:jar:1.19.0:compile
[INFO] |  |           |  \- com.googlecode.json-simple:json-simple:jar:1.1.1:compile
[INFO] |  |           +- org.locationtech.proj4j:proj4j:jar:1.1.5:compile
[INFO] |  |           +- com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:jar:2.13.2:runtime
[INFO] |  |           +- com.google.uzaygezen:uzaygezen-core:jar:0.2:runtime
[INFO] |  |           +- com.jayway.jsonpath:json-path:jar:2.7.0:runtime
[INFO] |  |           |  \- net.minidev:json-smart:jar:2.4.7:runtime
[INFO] |  |           |     \- net.minidev:accessors-smart:jar:2.4.7:runtime
[INFO] |  |           |        \- org.ow2.asm:asm:jar:9.1:runtime
[INFO] |  |           +- com.yahoo.datasketches:sketches-core:jar:0.9.0:runtime
[INFO] |  |           |  \- com.yahoo.datasketches:memory:jar:0.9.0:runtime
[INFO] |  |           +- net.hydromatic:aggdesigner-algorithm:jar:6.0:runtime
[INFO] |  |           |  \- commons-logging:commons-logging:jar:1.1.3:runtime
[INFO] |  |           +- org.apache.commons:commons-dbcp2:jar:2.6.0:runtime
[INFO] |  |           |  \- org.apache.commons:commons-pool2:jar:2.6.1:runtime
[INFO] |  |           +- commons-io:commons-io:jar:2.11.0:runtime
[INFO] |  |           +- org.codehaus.janino:commons-compiler:jar:3.1.8:runtime
[INFO] |  |           \- org.codehaus.janino:janino:jar:3.1.8:runtime
[INFO] |  +- org.apache.shardingsphere:shardingsphere-sql-federation-executor-original:jar:5.2.1:compile
[INFO] |  +- org.apache.shardingsphere:shardingsphere-parser-core:jar:5.2.1:compile
[INFO] |  |  +- org.apache.shardingsphere:shardingsphere-parser-api:jar:5.2.1:compile
[INFO] |  |  \- org.apache.shardingsphere:shardingsphere-infra-parser:jar:5.2.1:compile
[INFO] |  +- org.apache.commons:commons-collections4:jar:4.4:compile
[INFO] |  +- com.h2database:h2:jar:2.1.214:runtime
[INFO] |  +- com.google.guava:guava:jar:30.0-jre:compile
[INFO] |  |  +- com.google.guava:failureaccess:jar:1.0.1:compile
[INFO] |  |  +- com.google.code.findbugs:jsr305:jar:3.0.2:compile
[INFO] |  |  +- org.checkerframework:checker-qual:jar:3.5.0:compile
[INFO] |  |  \- com.google.errorprone:error_prone_annotations:jar:2.3.4:compile
[INFO] |  +- org.slf4j:jcl-over-slf4j:jar:1.7.36:compile
[INFO] |  \- org.slf4j:jul-to-slf4j:jar:1.7.36:compile
[INFO] +- org.yaml:snakeyaml:jar:1.33:compile
[INFO] +- cn.easyproject:ojdbc6:jar:12.1.0.2.0:compile
[INFO] +- org.springframework:spring-test:jar:5.0.4.RELEASE:compile
[INFO] +- org.springframework:spring-context-support:jar:5.0.4.RELEASE:compile
[INFO] |  +- org.springframework:spring-beans:jar:5.0.4.RELEASE:compile
[INFO] |  \- org.springframework:spring-context:jar:5.0.4.RELEASE:compile
[INFO] |     +- org.springframework:spring-aop:jar:5.0.4.RELEASE:compile
[INFO] |     \- org.springframework:spring-expression:jar:5.0.4.RELEASE:compile
[INFO] +- org.springframework:spring-tx:jar:5.0.4.RELEASE:compile
[INFO] +- org.springframework:spring-core:jar:5.0.4.RELEASE:compile
[INFO] |  \- org.springframework:spring-jcl:jar:5.0.4.RELEASE:compile
[INFO] +- org.springframework:spring-jdbc:jar:5.0.4.RELEASE:compile
[INFO] +- org.mybatis:mybatis-spring:jar:1.3.0:compile
[INFO] +- junit:junit:jar:4.13.2:test
[INFO] |  \- org.hamcrest:hamcrest-core:jar:1.3:test
[INFO] +- org.slf4j:slf4j-api:jar:1.7.7:compile
[INFO] +- org.slf4j:slf4j-log4j12:jar:1.7.7:compile
[INFO] +- log4j:log4j:jar:1.2.17:compile
[INFO] +- org.apache.logging.log4j:log4j-slf4j-impl:jar:2.19.0:test
[INFO] |  +- org.apache.logging.log4j:log4j-api:jar:2.19.0:test
[INFO] |  \- org.apache.logging.log4j:log4j-core:jar:2.19.0:test
[INFO] \- mysql:mysql-connector-java:jar:5.1.35:compile
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  2.591 s
[INFO] Finished at: 2023-01-30T08:41:30+08:00
[INFO] ------------------------------------------------------------------------
Exception in thread "main" Cannot create property=rules for JavaBean=org.apache.shardingsphere.infra.yaml.config.pojo.YamlRootConfiguration@291ae
 in 'reader', line 1, column 1:
    databaseName: oracleSource
    ^
No single argument constructor found for interface org.apache.shardingsphere.infra.yaml.config.pojo.rule.YamlRuleConfiguration
 in 'reader', line 37, column 5:
        tables:
        ^

    at org.yaml.snakeyaml.constructor.Constructor$ConstructMapping.constructJavaBean2ndStep(Constructor.java:321)
    at org.yaml.snakeyaml.constructor.Constructor$ConstructMapping.construct(Constructor.java:207)
    at org.yaml.snakeyaml.constructor.Constructor$ConstructYamlObject.construct(Constructor.java:358)
    at org.yaml.snakeyaml.constructor.BaseConstructor.constructObjectNoCheck(BaseConstructor.java:270)
    at org.yaml.snakeyaml.constructor.BaseConstructor.constructObject(BaseConstructor.java:253)
    at org.yaml.snakeyaml.constructor.BaseConstructor.constructDocument(BaseConstructor.java:207)
    at org.yaml.snakeyaml.constructor.BaseConstructor.getSingleData(BaseConstructor.java:191)
    at org.yaml.snakeyaml.Yaml.loadFromReader(Yaml.java:477)
    at org.yaml.snakeyaml.Yaml.loadAs(Yaml.java:443)
    at org.apache.shardingsphere.infra.util.yaml.YamlEngine.unmarshal(YamlEngine.java:55)
    at org.apache.shardingsphere.driver.api.yaml.YamlShardingSphereDataSourceFactory.createDataSource(YamlShardingSphereDataSourceFactory.java:61)
    at Test.main(Test.java:30)
Caused by: org.yaml.snakeyaml.error.YAMLException: No single argument constructor found for interface org.apache.shardingsphere.infra.yaml.config.pojo.rule.YamlRuleConfiguration
    at org.yaml.snakeyaml.constructor.Constructor$ConstructScalar.construct(Constructor.java:417)
    at org.yaml.snakeyaml.constructor.BaseConstructor.constructObjectNoCheck(BaseConstructor.java:270)
    at org.yaml.snakeyaml.constructor.BaseConstructor.constructObject(BaseConstructor.java:253)
    at org.yaml.snakeyaml.constructor.SafeConstructor.processDuplicateKeys(SafeConstructor.java:108)
    at org.yaml.snakeyaml.constructor.SafeConstructor.flattenMapping(SafeConstructor.java:81)
    at org.yaml.snakeyaml.constructor.SafeConstructor.flattenMapping(SafeConstructor.java:76)
    at org.yaml.snakeyaml.constructor.SafeConstructor.constructSet2ndStep(SafeConstructor.java:218)
    at org.yaml.snakeyaml.constructor.BaseConstructor.constructSet(BaseConstructor.java:545)
    at org.yaml.snakeyaml.constructor.Constructor$ConstructMapping.construct(Constructor.java:199)
    at org.yaml.snakeyaml.constructor.BaseConstructor.constructObjectNoCheck(BaseConstructor.java:270)
    at org.yaml.snakeyaml.constructor.BaseConstructor.constructObject(BaseConstructor.java:253)
    at org.yaml.snakeyaml.constructor.Constructor$ConstructMapping.newInstance(Constructor.java:333)
    at org.yaml.snakeyaml.constructor.Constructor$ConstructMapping.constructJavaBean2ndStep(Constructor.java:298)
    ... 11 more

I think the key is this,

No single argument constructor found for interface org.apache.shardingsphere.infra.yaml.config.pojo.rule.YamlRuleConfiguration

But why is this a problem

790477691 commented 1 year ago

@RaigorJiang

org.apache.shardingsphere:shardingsphere-infra-common:5.3.1
package org.apache.shardingsphere.infra.yaml.config.pojo.rule;

import org.apache.shardingsphere.infra.config.rule.RuleConfiguration;
import org.apache.shardingsphere.infra.util.yaml.YamlConfiguration;

/**
 * YAML rule configuration.
 */
public interface YamlRuleConfiguration extends YamlConfiguration {

    /**
     * Get rule configuration type.
     * 
     * @return rule configuration type
     */
    Class<? extends RuleConfiguration> getRuleConfigurationType();
}

This interface really doesn't have a single argument constructor

790477691 commented 1 year ago

Get the interface YamlRuleConfiguration constructor to return an empty array and error 微信截图_20230130095157

zhaojinchao95 commented 1 year ago

@790477691 Can you provide a demo project?

790477691 commented 1 year ago

@zhaojinchao95 Here's a test project https://github.com/790477691/shardingJdbcTest.git

790477691 commented 1 year ago

@zhaojinchao95 shardingsphere jdbc + spring; Are there any examples that can be used?

RaigorJiang commented 1 year ago

@790477691
Use example-generator to generate various example projects. https://github.com/apache/shardingsphere/tree/master/examples/shardingsphere-example-generator

RaigorJiang commented 1 year ago

@790477691 I think it is duplicated with #23143, can you have a check?