{"id":10008194,"date":"2023-08-30T12:00:35","date_gmt":"2023-08-30T04:00:35","guid":{"rendered":"https:\/\/blog.itmax.cn\/?p=10008194"},"modified":"2023-08-30T12:00:35","modified_gmt":"2023-08-30T04:00:35","slug":"%e7%a0%b4%e5%b1%80%e4%b8%bb%e9%94%ae%e9%87%8d%e5%a4%8d%e9%97%ae%e9%a2%98%e7%9a%84%e5%9d%8e%e5%9d%b7%e8%b7%af-%e4%ba%ac%e4%b8%9c%e7%89%a9%e6%b5%81%e6%8a%80%e6%9c%af%e5%9b%a2%e9%98%9f","status":"publish","type":"post","link":"https:\/\/itmax.cn\/?p=10008194","title":{"rendered":"\u7834\u5c40\u4e3b\u952e\u91cd\u590d\u95ee\u9898\u7684\u574e\u5777\u8def | \u4eac\u4e1c\u7269\u6d41\u6280\u672f\u56e2\u961f"},"content":{"rendered":"<p>\u4f34\u968f\u7740\u4e1a\u52a1\u7684\u4e0d\u65ad\u53d1\u5c55\uff0c\u9010\u6e10\u7531\u5355\u5e93\u5355\u8868\u5411\u5206\u5e93\u5206\u8868\u8fdb\u884c\u53d1\u5c55\u3002\u5728\u8fd9\u4e2a\u8fc7\u7a0b\u4e2d\u4e0d\u53ef\u907f\u514d\u7684\u4e00\u4e2a\u95ee\u9898\u662f\u786e\u4fdd\u4e3b\u952e\u8981\u7684\u552f\u4e00\u6027\uff0c\u4ee5\u4fbf\u4e8e\u540e\u7eed\u7684\u6570\u636e\u805a\u5408\u3001\u5206\u6790\u7b49\u7b49\u573a\u666f\u7684\u4f7f\u7528\u3002\u5728\u8fdb\u884c\u5206\u5e93\u5206\u8868\u7684\u89e3\u51b3\u65b9\u6848\u4e2d\u6709\u591a\u79cd\u6280\u672f\u9009\u578b\uff0c\u5927\u6982\u5206\u4e3a\u4e24\u5927\u7c7b\u5ba2\u6237\u7aef\u5206\u5e93\u5206\u8868\u3001\u670d\u52a1\u7aef\u5206\u5e93\u5206\u8868\u3002\u4f8b\u5982 Sharding-JDBC\u3001ShardingSphere\u3001 MyCat\u3001 ShardingSphere-Proxy\u3001Jproxy(\u4eac\u4e1c\u5185\u90e8\u5df2\u5f03\u7528)\u7b49\u7b49\u3002<\/p>\n<p>\u5728\u8fd9\u4e2a\u71e5\u70ed\u7684\u590f\u5929\uff0c\u53c8\u7a81\u7136\u6536\u5230\u544a\u8b66\uff0c\u5206\u5e93\u5206\u8868\u7684\u4e3b\u952e\u51b2\u7a81\u4e86\uff0c\u8fd9\u8fd8\u80fd\u5fcd\uff1f\u4e0d\uff0c\u575a\u51b3\u4e0d\u80fd\u5fcd\uff0c\u5fc5\u987b\u89e3\u51b3\u6389\uff01\u540e\u9762\u54b1\u4eec\u6162\u6162\u9053\u6765\u662f\u5982\u4f55\u7834\u5c40\u7684\uff0c\u5982\u4f55\u8d70\u4e86\u4e00\u6761\u574e\u5777\u8def\u2026\u2026<\/p>\n<h2>\u7ffb\u5c71\u7b2c\u4e00\u6b65<\/h2>\n<p>\u54b1\u4eec\u7684\u7cfb\u7edf\u4f7f\u7528\u7684\u662fShardingSphere\u8fdb\u884c\u5206\u5e93\u5206\u8868\u7684\uff0c\u5927\u6982\u7684\u914d\u7f6e\u4fe1\u606f\u5982\u4e0b\uff1a_\uff08\u51fa\u4e8e\u4fe1\u606f\u7684\u5b89\u5168\u8003\u8651\uff0c\u9690\u85cf\u4e86\u90e8\u5206\u4fe1\u606f\uff0c\u53ea\u4fdd\u7559\u7684\u90e8\u5206\u5185\u5bb9\uff0c\u4e0d\u8981\u5728\u610f\u8fd9\u4e9b\u7ec6\u8282\u80fd\u8bf4\u660e\u95ee\u9898\u5373\u53ef\uff09_<\/p>\n<pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;\n&lt;beans xmlns=&quot;http:\/\/www.springframework.org\/schema\/beans&quot;\n       xmlns:xsi=&quot;http:\/\/www.w3.org\/2001\/XMLSchema-instance&quot;\n       xmlns:sharding=&quot;http:\/\/shardingsphere.apache.org\/schema\/shardingsphere\/sharding&quot;\n       xsi:schemaLocation=&quot;http:\/\/www.springframework.org\/schema\/beans\n       http:\/\/www.springframework.org\/schema\/beans\/spring-beans.xsd http:\/\/shardingsphere.apache.org\/schema\/shardingsphere\/sharding http:\/\/shardingsphere.apache.org\/schema\/shardingsphere\/sharding\/sharding.xsd&quot;&gt;\n\n    &lt;!--\u6570\u636e\u6e90--&gt;\n    &lt;bean id=&quot;database1&quot; class=&quot;com.alibaba.druid.pool.DruidDataSource&quot; destroy-method=&quot;close&quot;&gt;\n    &lt;\/bean&gt;\n    &lt;bean id=&quot;database2&quot; class=&quot;com.alibaba.druid.pool.DruidDataSource&quot; destroy-method=&quot;close&quot;&gt;\n    &lt;\/bean&gt;\n    &lt;bean id=&quot;database3&quot; class=&quot;com.alibaba.druid.pool.DruidDataSource&quot; destroy-method=&quot;close&quot;&gt;\n    &lt;\/bean&gt;\n\n    &lt;sharding:inline-strategy id=&quot;databaseStrategy&quot; sharding-column=&quot;cloum1&quot; algorithm-expression=&quot;table1_$-&gt;{(Math.abs(cloum1.hashCode()) % 512).intdiv(32) }&quot; \/&gt;\n    &lt;sharding:inline-strategy id=&quot;orderNoDatabaseStrategy&quot; sharding-column=&quot;cloum2&quot; algorithm-expression=&quot;table2_$-&gt;{(Math.abs(cloum2.hashCode()) % 512).intdiv(32) }&quot; \/&gt;\n    &lt;sharding:inline-strategy id=&quot;businessNoDatabaseStrategy&quot; sharding-column=&quot;cloum3&quot; algorithm-expression=&quot;table3_$-&gt;{(Math.abs(cloum3.hashCode()) % 512).intdiv(32) }&quot; \/&gt;\n    &lt;!-- \u4e3b\u952e\u751f\u6210\u7b56\u7565 -\u96ea\u82b1\u7b97\u6cd5--&gt;\n    &lt;sharding:key-generator id=&quot;idKeyGenerator&quot; type=&quot;SNOWFLAKE&quot; column=&quot;id&quot; props-ref=&quot;snowFlakeProperties&quot;\/&gt;\n\n    &lt;sharding:data-source id=&quot;dataSource&quot;&gt;\n        &lt;sharding:sharding-rule data-source-names=&quot;database1,database2,database3&quot;&gt;\n            &lt;sharding:table-rules&gt;\n\n                &lt;sharding:table-rule logic-table=&quot;table1&quot;\n                                     actual-data-nodes=&quot;database1_$-&gt;{0..15}.table1_$-&gt;{0..31}&quot;\n                                     database-strategy-ref=&quot;orderNoDatabaseStrategy&quot;\n                                     table-strategy-ref=&quot;order_waybill_tableStrategy&quot;\n                                     key-generator-ref=&quot;idKeyGenerator&quot;\/&gt;\n\n                &lt;sharding:table-rule logic-table=&quot;table2&quot;\n                                     actual-data-nodes=&quot;database2_$-&gt;{0..15}.table2_$-&gt;{0..31}&quot;\n                                     database-strategy-ref=&quot;databaseStrategy&quot;\n                                     table-strategy-ref=&quot;waybill_contacts_tableStrategy&quot;\n                                     key-generator-ref=&quot;idKeyGenerator&quot;\/&gt;\n\n                &lt;sharding:table-rule logic-table=&quot;table3&quot;\n                                     actual-data-nodes=&quot;database3_$-&gt;{0..15}.table3-&gt;{0..31}&quot;\n                                     database-strategy-ref=&quot;databaseStrategy&quot;\n                                     table-strategy-ref=&quot;waybill_tableStrategy&quot;\n                                     key-generator-ref=&quot;idKeyGenerator&quot;\/&gt;\n            &lt;\/sharding:table-rules&gt;\n        &lt;\/sharding:sharding-rule&gt;\n    &lt;\/sharding:data-source&gt;\n\n\n    &lt;bean id=&quot;sqlSessionFactory&quot; class=&quot;com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean&quot;&gt;\n        &lt;property name=&quot;dataSource&quot; ref=&quot;dataSource&quot; \/&gt;\n        &lt;property name=&quot;configLocation&quot; value=&quot;classpath:spring\/mybatis-env-setting.xml&quot;\/&gt;\n        &lt;property name=&quot;mapperLocations&quot; value=&quot;classpath*:\/mapper\/*.xml&quot;\/&gt;\n    &lt;\/bean&gt;\n\n&lt;\/beans&gt;\n\n\n\n<\/code><\/pre>\n<p>\u4ece\u4e0a\u9762\u7684\u914d\u7f6e\u53ef\u4ee5\u770b\u51fa\u914d\u7f6e\u7684\u662f&#8221;SNOWFLAKE&#8221; \u4e3b\u952e\u4f7f\u7528\u7684\u662f\u96ea\u82b1\u7b97\u6cd5\uff0c\u96ea\u82b1\u7b97\u6cd5\u4ea7\u751f\u7684ID\u7684\u7ec4\u6210\u603b\u8ba164\u4f4d\uff0c\u7b2c\u4e00\u4f4d\u4e3a\u7b26\u53f7\u4f4d\u4e0d\u7528\uff0c\u540e41\u4f4d\u4e3a\u65f6\u95f4\u6233\u7528\u4e8e\u533a\u522b\u4e0d\u540c\u7684\u65f6\u95f4\u70b9\uff0c\u5728\u540e\u976210\u4f4d\u4e3aworkId\u7528\u4e8e\u533a\u522b\u4e0d\u540c\u7684\u673a\u5668\uff0c\u6700\u540e12\u4f4d\u4e3asequence\u7528\u4e8e\u540c\u4e00\u65f6\u523b\u540c\u4e00\u673a\u5668\u7684\u5e76\u53d1\u6570\u91cf\u3002<\/p>\n<p><img decoding=\"async\"   referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000044164573\" alt=\"\" title=\"\"><\/p>\n<p>\u90a3\u63a5\u4e0b\u6765\u5c31\u770b\u770b\u54b1\u4eec\u81ea\u5df1\u7684\u7cfb\u7edf\u662f\u600e\u4e48\u914d\u7f6e\u7684\u5427,\u5176\u4e2d\u7684\u5c5e\u6027snowFlakeProperties\u914d\u7f6e\u5982\u4e0b,\u5176\u4e2d\u7684max.vibration.offset\u914d\u7f6e\u8868\u793asequence\u7684\u8303\u56f4\u4e3a1024\u3002\u6309\u7167\u6b63\u5e38\u7684\u7406\u89e3\u4efb\u4f55\u5355\u4e2a\u673a\u5668\u7684\u914d\u7f6e\u90fd\u5f88\u96be\u8fbe\u5230\u8fd9\u4e2a\u5e76\u53d1\u91cf\uff0c\u96be\u9053\u662f\u8fd9\u4e2a\u503c\u6ca1\u6709\u751f\u6548\uff1f<\/p>\n<pre><code>    &lt;sharding:key-generator id=&quot;idKeyGenerator&quot; type=&quot;SNOWFLAKE&quot; column=&quot;id&quot; props-ref=&quot;snowFlakeProperties&quot;\/&gt;\n\n\n\n<\/code><\/pre>\n<p><img decoding=\"async\"   referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000044164575\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<p>shardingsphere\u4e2d\u5b9e\u73b0\u83b7\u53d6\u4e3b\u952e\u7684\u5b9e\u73b0\u6e90\u7801\u5982\u4e0b\u7b80\u8ff0\uff0c\u5177\u4f53\u7684\u5b9e\u73b0\u7c7borg.apache.shardingsphere.core.strategy.keygen.SnowflakeShardingKeyGenerator,\u4ece\u6e90\u7801\u770b\u6e90\u7801\u7adf\u7136\u4e00\u4e2a\u65e5\u5fd7\u90fd\u6ca1\u6709\uff0c\u90a3\u8ba9\u54b1\u4eec\u600e\u4e48\u53bb\u6392\u67e5\u5462\uff1f\u600e\u4e48\u8bc1\u660e\u54b1\u4eec\u7684\u731c\u60f3\u662f\u5426\u6b63\u786e\u7684\u5462\uff1f\u56e7\u2026\u2026<\/p>\n<p><img decoding=\"async\"   referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000044164576\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<p>\u771f\u662f\u8d25\u4e5f\u8427\u4f55\u6210\u4e5f\u8427\u4f55\uff0cshardingsphere\u662f\u901a\u8fc7java\u7684SPI\u7684\u65b9\u5f0f\u8fdb\u884c\u7684\u4e3b\u952e\u751f\u6210\u7b56\u7565\u7684\u6269\u5c55\u3002\u81ea\u5b9a\u4e49\u5b9e\u73b0\u65b9\u5f0f\u5982\u4e0b\uff1a\u5b9e\u73b0org.apache.shardingsphere.spi.keygen.ShardingKeyGenerator\u63a5\u53e3\uff0c\u5982\u679c\u81ea\u5df1\u60f3\u8981\u5b9e\u73b0\u4f7f\u7528SPI\u65b9\u5f0f\u8fdb\u884c\u52a0\u8f7d\u5373\u53ef\uff0c\u90a3\u5c31\u8ba9\u54b1\u4eec\u81ea\u5df1\u52a0\u65e5\u5fd7\u5427\uff0c\u8d70\u4f60\u2026\u2026<\/p>\n<p><img decoding=\"async\"   referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000044164577\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<p>\u65e2\u7136\u90fd\u81ea\u5df1\u5199\u5b9e\u73b0\u4e86\uff0c\u90a3\u65e5\u5fd7\u5c31\u8be5\u52a0\u7684\u90fd\u52a0\u5427\uff0c\u54b1\u8fd9\u7edd\u4e0d\u541d\u556c\u8fd9\u51e0\u884c\u65e5\u5fd7<\/p>\n<p><img decoding=\"async\"   referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000044164578\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<p>\u4fee\u6539\u4e3b\u952e\u9009\u62e9\u751f\u6210\u7b56\u7565\u4e3a\u81ea\u5df1\u5b9e\u73b0\u7684\u7c7b type=&#8221;MYSNOWFLAKE&#8221;<\/p>\n<pre><code>    &lt;sharding:key-generator id=&quot;idKeyGenerator&quot; type=&quot;MYSNOWFLAKE&quot; column=&quot;id&quot; props-ref=&quot;snowFlakeProperties&quot;\/&gt;\n\n\n\n<\/code><\/pre>\n<p>\u542f\u52a8\u770b\u65e5\u5fd7\uff0c\u5c5e\u6027\u4e2d\u6709max.vibration.offset=1024\u8fd9\u4e2a\u5c5e\u6027\uff0c\u7adf\u7136\u4f9d\u65e7\u62ff\u5230\u7684\u8fd8\u662f\u9ed8\u8ba4\u7684\u503c1\uff0c\u60ca\u8bb6\u4e2d\uff0c\u7ec6\u7ec6\u4e00\u7785\uff0c\u7ec8\u7a76\u53d1\u73b0\u4e86\u95ee\u9898\uff0c\u5728getProperty(key)\u65f6\u5982\u679c\u8fd4\u56de\u7684\u4e0d\u662fString\u7c7b\u578b\u90a3\u4e48\u4e3anull\uff0c\u8fdb\u800c\u53d6\u503c\u9ed8\u8ba4\u503c1\u3002\u4ece\u54b1\u4eec\u7684\u7cfb\u7edf\u914d\u7f6e\u4e2d\u53ef\u4ee5\u770b\u5230\u7cfb\u7edf\u914d\u7f6e\u7684int\u7c7b\u578b\u7684\u76841024\uff0c\u6240\u4ee5\u53d6\u503c\u9ed8\u8ba4\u503c1\u5c31\u8bf4\u901a\u4e86\u3002<\/p>\n<pre><code>INFO 2023-08-17 14:07:51.062 2174320.63604.16922524693996408 176557 com.jd.las.waybill.center.config.MySnowflakeShardingKeyGenerator.getMaxVibrationOffset(MySnowflakeShardingKeyGenerator.java:107) -- \u9009\u62e9\u81ea\u5b9a\u4e49\u7684\u96ea\u82b1\u7b97\u6cd5\u83b7\u53d6\u5230\u7684properties={&quot;max.vibration.offset&quot;:1024,&quot;worker.id&quot;:&quot;217&quot;,&quot;max.tolerate.time.difference.milliseconds&quot;:&quot;3000&quot;}\nINFO 2023-08-17 14:07:51.063 2174320.63604.16922524693996408 176558 com.jd.las.waybill.center.config.MySnowflakeShardingKeyGenerator.getMaxVibrationOffset(MySnowflakeShardingKeyGenerator.java:110) -- \u9009\u62e9\u81ea\u5b9a\u4e49\u7684\u96ea\u82b1\u7b97\u6cd5\u83b7\u53d6\u5230\u7684getMaxVibrationOffset=1\n\n\n\n<\/code><\/pre>\n<p><img decoding=\"async\"   referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000044164579\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<p><img decoding=\"async\"   referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000044164580\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<p>\u622a\u6b62\u5230\u76ee\u524d\u4e3b\u952e\u91cd\u590d\u7684\u95ee\u9898\u7ec8\u4e8e\u53ef\u4ee5\u89e3\u91ca\u7684\u901a\u4e86\uff0c\u56e0\u4e3a\u5e76\u53d1\u652f\u6301\u7684\u662f0~1\u603b\u51712\u4e2a\u5e76\u53d1\uff0c\u6240\u4ee5\u5728\u751f\u4ea7\u7cfb\u7edf\u4e2d\u5c24\u5176\u51fa\u73b0\u751f\u4ea7\u6ce2\u6b21\u7684\u65f6\u5019\u51fa\u73b0\u91cd\u590d\u503c\u7684\u53ef\u80fd\u6027\u662f\u5b58\u5728\u7684,\u7136\u540e\u628a1024\u53d8\u6210\u5b57\u7b26\u4e32\u4fee\u6539\u4e0a\u7ebf\uff0c\u76f8\u4fe1\u7cfb\u7edf\u540e\u9762\u5e94\u8be5\u4e0d\u4f1a\u4ea7\u751f\u6b64\u7c7b\u95ee\u9898\u4e86\u3002<\/p>\n<h2>\u8d8a\u5cad\u7b2c\u4e8c\u6b65<\/h2>\n<p>\u5982\u679c\u751f\u6d3b\u603b\u662f\u559c\u6b22\u8ddf\u4f60\u5f00\u73a9\u7b11\uff0c\u9017\u4f60\u73a9\uff0c\u90a3\u4f60\u5c31\u914d\u5408\u5b83\u7b11\u4e00\u7b11\u5427\u3002<\/p>\n<p>\u5f53\u4e0a\u5b8c\u7ebf\u540e\uff0c\u8fc7\u4e86\u4e00\u6bb5\u65f6\u95f4\u53d1\u73b0\u91cd\u590d\u4e3b\u952e\u7684\u95ee\u9898\u7adf\u7136\u4f9d\u65e7\u5b58\u5728\u53ea\u662f\u9891\u7387\u5c11\u4e86\u4e9b,\u4e0d\u79d1\u5b66\u5440\u2026\u2026<\/p>\n<p>\u91cd\u65b0\u68b3\u7406\u601d\u8def\uff0c\u8fdb\u884c\u66f4\u8be6\u7ec6\u7684\u65e5\u5fd7\u8f93\u51fa\uff0c\u4e0b\u5355\u8fdb\u884c\u9a8c\u8bc1\uff0c\u5c06\u63a5\u5355\u843d\u5e93\u8fd9\u5768\u4ee3\u7801\u4e00\u5e76\u90fd\u52a0\u4e0a\u65e5\u5fd7\u4ee5\u53ca\u89e6\u53d1\u96ea\u82b1\u7b97\u6cd5\u7684\u751f\u6210\u7684ID\u4e5f\u52a0\u4e0a\u65e5\u5fd7<\/p>\n<p><img decoding=\"async\"   referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000044164581\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<p><img decoding=\"async\"   referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000044164582\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<p>\u901a\u8fc7\u65e5\u5fd7\u5206\u6790\uff0c\u53c8\u53c8\u53c8\u53d1\u73b0&#8221;\u7075\u5f02\u4e8b\u4ef6&#8221;\uff0c10\u6761\u63d2\u5165SQL\uff0c\u53ea\u6709\u4e24\u6761\u89e6\u53d1\u4e86shardingsphere\u7684\u96ea\u82b1\u7b97\u6cd5\uff0c\u8be7\u5f02\u7684\u5f88\u5440~<\/p>\n<p><img decoding=\"async\"   referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000044164583\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<p>\u67e5\u770b\u5176\u4ed68\u5f20\u8868\u843d\u5e93\u7684ID\u6570\u636e\u5982\u4e0b\u56fe\uff0cID(1692562397556875266) \u90fd\u4e3a1692\u5f00\u5934\u4e14\u957f\u5ea620\u4f4d\uff0c\u800cshardingsphere\u4ea7\u751f\u7684ID\uff08899413419526356993\uff09\u90fd\u4e3a899\u5f00\u5934\u4e14\u957f\u5ea619\u4f4d\uff0c\u5f88\u660e\u663e\u8fd98\u5f20\u8868\u7684\u4e3b\u952e\u4e0d\u662fshardingsphere\u751f\u6210\u7684\uff0c\u90a3\u662f\u8fd920\u4f4d\u7684\u6570\u636e\u54ea\u6765\u7684\u5462\uff1f\uff1f\uff1f\u4eceID\u4e0a\u770b\u660e\u663e\u4e5f\u4e0d\u662f\u81ea\u589e\u4ea7\u751f\u7684\u4e3b\u952e\uff0c\u53c8\u4e0d\u79d1\u5b66\u4e86\u2026\u2026<\/p>\n<p><img decoding=\"async\"   referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000044164584\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<p>\u53c8\u662f\u4e00\u4e2a\u6df1\u591c\u2026\u2026<\/p>\n<p>\u68b3\u7406\u601d\u8def\u91cd\u65b0\u5728\u950a\uff0c\u4e3b\u952e\u76f8\u5173\u7684\u9664\u4e86\u6570\u636e\u81ea\u589e\u957f\u3001shardingsphere\u914d\u7f6e\u7684\u96ea\u82b1\u8fd8\u6709\u552f\u4e00\u7684\u4e00\u4e2a\u76f8\u5173\u7684\u7ec4\u4ef6\u90a3\u5c31\u662fmybatis\uff0c\u7531\u4e8e\u9879\u76ee\u662f\u5f88\u65e9\u4e4b\u524d\u7684\u5e94\u7528\u4e86\uff0c\u4f7f\u7528\u7684\u662fbaomidou\u7684mybaits\u63d2\u4ef6\uff0c\u5982\u56fe\u662f\u63d2\u4ef6\u7684\u5165\u53e3\uff0cMybatisSqlSessionFactoryBean\u5b9e\u73b0FactoryBean&lt;SqlSessionFactory&gt;, InitializingBean, ApplicationListener&lt;ApplicationEvent&gt;\u51e0\u4e2aSpring\u7684\u63a5\u53e3<\/p>\n<p><img decoding=\"async\"   referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000044164585\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<p>baomidou\u6d89\u53ca\u8be5\u5757\u95ee\u9898\u7684\u6e90\u7801\u5982\u4e0b\uff1a<\/p>\n<p><img decoding=\"async\"   referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000044164586\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<p>\u5982\u679cGlobalConfig\u6ca1\u6709\u914d\u7f6eworkId\u548cDataCenterId\u4f1a\u4f7f\u7528\u65e0\u53c2\u6784\u9020\uff0c\u9ed8\u8ba4\u7684workId<\/p>\n<p><img decoding=\"async\"   referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000044164587\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<p><img decoding=\"async\"   referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000044164588\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<p><img decoding=\"async\"   referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000044164589\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<p>baomidou\u7684\u96ea\u82b1\u7b97\u6cd5\u548cshardingphere\u601d\u8def\u4e00\u81f4\u6709\u4e00\u70b9\u70b9\u533a\u522b\u5728\u4e8e\u7b2c12\u4f4d\u548c22\u4f4d\u6709datacenter&lt;&lt;17|workId&lt;&lt;12\u83b7\u53d6\uff0c\u4e14datacenter\u548cworkId\u9700\u8981\u57280~31\u4e4b\u95f4<\/p>\n<p><img decoding=\"async\"   referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000044164590\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<p>\u4e0d\u540c\u673a\u5668\u7684Name\uff1a<\/p>\n<p><img decoding=\"async\"   referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000044164591\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<p><img decoding=\"async\"   referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000044164592\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<p>\u6240\u4ee5\u53c8\u89e3\u91ca\u4e86\u4e3a\u4ec0\u4e48\u4e0d\u540c\u673a\u5668\u4f1a\u51fa\u73b0\u76f8\u540c\u7684\u4e3b\u952e\u95ee\u9898\uff0c\u4f46\u662f\u5982\u679c\u6709\u7ec6\u5fc3\u7684\u540c\u5b66\u5c31\u4f1a\u95ee\u4e3a\u556510\u5f20\u8868\u4e2d\u67098\u5f20\u8868\u8d70\u7684\u662fbaomidou\u7684\u96ea\u82b1\u7b97\u6cd5\u5462\uff0c\u90a3\u662f\u56e0\u4e3abaomidou\u4f1a\u5224\u65ad\u4fdd\u5b58\u7684\u5165\u53c2\u5b9e\u4f53bean\u4e0a\u662f\u5426\u6709id\u5b57\u6bb5\uff0c\u662f\u5426\u80fd\u5339\u914d\u4e0a\u8be5\u5b57\u6bb5\uff0c\u5982\u679c\u5b58\u5728\u5219\u5728baomidou\u8fd9\u5c42\u5c31\u7ed9\u8d4b\u503c\u4e86baomidou\u96ea\u82b1\u7b97\u6cd5\u751f\u4ea7\u7684ID\uff0c\u540e\u7eed\u5c31\u4e0d\u4f1a\u518d\u6b21\u89e6\u53d1shardingsphere\u4e2dID\u751f\u6210\uff0c\u8fdb\u800c\u5bfc\u81f4\u8be5\u95ee\u9898\u3002<\/p>\n<p>\u622a\u6b62\u5230\u76ee\u524d\u7ec8\u4e8e\u53c8\u89e3\u91ca\u901a\u4e86\u4e3a\u4ec0\u4e48\u8de8\u673a\u5668\u4f1a\u4ea7\u751f\u76f8\u540c\u7684\u4e3b\u952e\u95ee\u9898\u3002<\/p>\n<p>\u95ee\u9898\u7684\u89e3\u51b3\u65b9\u5f0f\uff1a<\/p>\n<p>baomidou\u914d\u7f6e\u7684\u8fc7\u7a0b\u4e2d\u6307\u5b9aworkId\u548ccenterDataId\uff0c\u4f46\u662f\u9700\u8981\u786e\u4fddcenterDataId&lt;&lt;17|workId&lt;&lt;12\u786e\u4fdd\u552f\u4e00\u3002\u7c7b\u6bd4shardingphere\uff0c\u501f\u7528shardingphere\u4e2d\u768412~22\u4f4d\u552f\u4e00\u6570\uff0c\u524d5\u9ad8\u4f4d\u7ed9(centerDataId&lt;&lt;17),\u540e5\u4f4e\u4f4d\u7ed9workId&lt;&lt;12;<\/p>\n<p><img decoding=\"async\"   referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000044164593\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<p>\u591c\u5df2\u6c89\u9ed8\u2026\u2026<\/p>\n<p>\u751f\u4ea7\u73af\u5883\u5df2\u4e0a\u7ebf\u9a8c\u8bc1\u901a\u8fc7<\/p>\n<blockquote>\n<p>\u4f5c\u8005\uff1a\u4eac\u4e1c\u7269\u6d41\u00a0\u738b\u4e49\u6770<\/p>\n<p>\u6765\u6e90\uff1a\u4eac\u4e1c\u4e91\u5f00\u53d1\u8005\u793e\u533a \u81ea\u733f\u5176\u8bf4Tech \u8f6c\u8f7d\u8bf7\u6ce8\u660e\u6765\u6e90<\/p>\n<\/blockquote>\n<p><a href=\"https:\/\/segmentfault.com\/a\/1190000044164571\">https:\/\/segmentfault.com\/a\/1190000044164571<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4f34\u968f\u7740\u4e1a\u52a1\u7684\u4e0d\u65ad\u53d1\u5c55\uff0c\u9010\u6e10\u7531\u5355\u5e93\u5355\u8868\u5411\u5206\u5e93\u5206\u8868\u8fdb\u884c\u53d1\u5c55\u3002\u5728\u8fd9\u4e2a\u8fc7\u7a0b\u4e2d\u4e0d\u53ef\u907f\u514d\u7684\u4e00\u4e2a\u95ee\u9898\u662f\u786e\u4fdd\u4e3b\u952e\u8981\u7684\u552f\u4e00\u6027\uff0c\u4ee5 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[4],"tags":[],"class_list":["post-10008194","post","type-post","status-publish","format-standard","hentry","category-share"],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts\/10008194","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=10008194"}],"version-history":[{"count":0,"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts\/10008194\/revisions"}],"wp:attachment":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=10008194"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=10008194"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=10008194"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}