开发者社区> 问答> 正文

主从下,分片demo启动报错怎么回事?报错

Initialized data sources can not be master-slave data sources.

展开
收起
爱吃鱼的程序员 2020-06-06 10:16:40 411 0
1 条回答
写回答
取消 提交回答
  • https://developer.aliyun.com/profile/5yerqm5bn5yqg?spm=a2c6h.12873639.0.0.6eae304abcjaIB
                        <p>使用的是官方提供的</p> 
    

     

    <bean id="demo_ds_master_0" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
            <property name="driverClassName" value="com.mysql.jdbc.Driver"/>
            <property name="url" value="jdbc:mysql://localhost:3306/demo_ds_master_0"/>
            <property name="username" value="root"/>
            <property name="password" value=""/>
        </bean>
        
        <bean id="demo_ds_master_0_slave_0" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
            <property name="driverClassName" value="com.mysql.jdbc.Driver"/>
            <property name="url" value="jdbc:mysql://localhost:3306/demo_ds_master_0_slave_0"/>
            <property name="username" value="root"/>
            <property name="password" value=""/>
        </bean>
        
        <bean id="demo_ds_master_0_slave_1" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
            <property name="driverClassName" value="com.mysql.jdbc.Driver"/>
            <property name="url" value="jdbc:mysql://localhost:3306/demo_ds_master_0_slave_1"/>
            <property name="username" value="root"/>
            <property name="password" value=""/>
        </bean>

        <bean id="demo_ds_master_1" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
            <property name="driverClassName" value="com.mysql.jdbc.Driver"/>
            <property name="url" value="jdbc:mysql://localhost:3306/demo_ds_master_1"/>
            <property name="username" value="root"/>
            <property name="password" value=""/>
        </bean>

        <bean id="demo_ds_master_1_slave_0" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
            <property name="driverClassName" value="com.mysql.jdbc.Driver"/>
            <property name="url" value="jdbc:mysql://localhost:3306/demo_ds_master_1_slave_0"/>
            <property name="username" value="root"/>
            <property name="password" value=""/>
        </bean>

        <bean id="demo_ds_master_1_slave_1" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
            <property name="driverClassName" value="com.mysql.jdbc.Driver"/>
            <property name="url" value="jdbc:mysql://localhost:3306/demo_ds_master_1_slave_1"/>
            <property name="username" value="root"/>
            <property name="password" value=""/>
        </bean>

        <bean id="randomStrategy" class="io.shardingsphere.core.api.algorithm.masterslave.RandomMasterSlaveLoadBalanceAlgorithm" />
        
        <master-slave:data-source id="demo_ds_ms_0" master-data-source-name="demo_ds_master_0" slave-data-source-names="demo_ds_master_0_slave_0, demo_ds_master_0_slave_1" strategy-ref="randomStrategy" />
        <master-slave:data-source id="demo_ds_ms_1" master-data-source-name="demo_ds_master_1" slave-data-source-names="demo_ds_master_1_slave_0, demo_ds_master_1_slave_1" strategy-ref="randomStrategy" />
        
        <sharding:inline-strategy id="databaseStrategy" sharding-column="user_id" algorithm-expression="demo_ds_ms_${user_id % 2}" />
        <sharding:inline-strategy id="orderTableStrategy" sharding-column="order_id" algorithm-expression="t_order_${order_id % 2}" />
        <sharding:inline-strategy id="orderItemTableStrategy" sharding-column="order_item_id" algorithm-expression="t_order_item_${order_item_id % 2}" />
        
        <sharding:data-source id="shardingDataSource">
            <sharding:sharding-rule data-source-names="demo_ds_ms_0,demo_ds_ms_1">
                <sharding:table-rules>
                    <sharding:table-rule logic-table="t_order" actual-data-nodes="demo_ds_ms_${0..1}.t_order_${0..1}" database-strategy-ref="databaseStrategy" table-strategy-ref="orderTableStrategy" />
                    <sharding:table-rule logic-table="t_order_item" actual-data-nodes="demo_ds_ms_${0..1}.t_order_item_${0..1}" database-strategy-ref="databaseStrategy" table-strategy-ref="orderItemTableStrategy" />
                </sharding:table-rules>
            </sharding:sharding-rule>
        </sharding:data-source>

     

    这个demo 

    2020-06-06 10:16:52
    赞同 展开评论 打赏
问答地址:
问答排行榜
最热
最新

相关电子书

更多
PostgreSQL复制原理及高可用集群 立即下载
Codis 集群演化与 Redis 异步迁移 立即下载
Data as a Service - 数据即服务 -- MongoDB⾼级应⽤模式 立即下载