pbootcms网站模板|日韩1区2区|织梦模板||网站源码|日韩1区2区|jquery建站特效-html5模板网

      <i id='Z6flf'><tr id='Z6flf'><dt id='Z6flf'><q id='Z6flf'><span id='Z6flf'><b id='Z6flf'><form id='Z6flf'><ins id='Z6flf'></ins><ul id='Z6flf'></ul><sub id='Z6flf'></sub></form><legend id='Z6flf'></legend><bdo id='Z6flf'><pre id='Z6flf'><center id='Z6flf'></center></pre></bdo></b><th id='Z6flf'></th></span></q></dt></tr></i><div class="tzprpv7" id='Z6flf'><tfoot id='Z6flf'></tfoot><dl id='Z6flf'><fieldset id='Z6flf'></fieldset></dl></div>
    1. <legend id='Z6flf'><style id='Z6flf'><dir id='Z6flf'><q id='Z6flf'></q></dir></style></legend>

      <small id='Z6flf'></small><noframes id='Z6flf'>

      • <bdo id='Z6flf'></bdo><ul id='Z6flf'></ul>
        <tfoot id='Z6flf'></tfoot>
      1. Spring/J2EE Apps 中的只讀和讀寫分離

        Segregating the read-only and read-write in Spring/J2EE Apps(Spring/J2EE Apps 中的只讀和讀寫分離)

          <tbody id='8bcKw'></tbody>
        • <bdo id='8bcKw'></bdo><ul id='8bcKw'></ul>
          <i id='8bcKw'><tr id='8bcKw'><dt id='8bcKw'><q id='8bcKw'><span id='8bcKw'><b id='8bcKw'><form id='8bcKw'><ins id='8bcKw'></ins><ul id='8bcKw'></ul><sub id='8bcKw'></sub></form><legend id='8bcKw'></legend><bdo id='8bcKw'><pre id='8bcKw'><center id='8bcKw'></center></pre></bdo></b><th id='8bcKw'></th></span></q></dt></tr></i><div class="fnrb5bt" id='8bcKw'><tfoot id='8bcKw'></tfoot><dl id='8bcKw'><fieldset id='8bcKw'></fieldset></dl></div>
            <tfoot id='8bcKw'></tfoot>

            <small id='8bcKw'></small><noframes id='8bcKw'>

                  <legend id='8bcKw'><style id='8bcKw'><dir id='8bcKw'><q id='8bcKw'></q></dir></style></legend>
                1. 本文介紹了Spring/J2EE Apps 中的只讀和讀寫分離的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我們在項目中使用 Spring、Spring-Data 和 JPA.

                  We using Spring, Spring-Data and JPA in our project.

                  對于生產服務器,我們希望設置數據庫集群,以便所有讀取查詢都指向一臺服務器,所有寫入查詢都指向另一臺服務器.

                  For production servers, we would like to setup database cluster such that all read queries are directed to one server and all write queries are directed to another server.

                  這顯然需要對 DAO 的構建方式進行一些更改.

                  This obviously will require some changes in the way the DAOs are built.

                  如果到目前為止,有人一直使用 Spring-Data/JPA 遵循食譜風格的 DAO 創建,其中 DAO 實現負責讀取和寫入,那么有誰知道如何實現這一點?需要在架構上進行什么樣的更改來隔離這兩種類型的調用?

                  Does anyone know how to achieve this if one has, so far, been following cook-book style DAO creations using Spring-Data/JPA where a DAO implementation is responsible for both reads and writes? What kind of changes in architecture will be needed to segregate the two types of calls?

                  推薦答案

                  在使用 MySQL 時,Java 開發人員通常使用 Connector/J 作為 JDBC 驅動程序.開發者通常使用Connector/J com.mysql.jdbc.Driver 類,通過諸如jdbc:mysql://host[:port]/database 的URL 來連接到 MySQL 數據庫.

                  When using MySQL, it is common for Java developers to use Connector/J as the JDBC driver. Developers typically use the Connector/J com.mysql.jdbc.Driver class, with a URL such as jdbc:mysql://host[:port]/database to connect to MySQL databases.

                  Connector/J 提供了另一個名為 ReplicationDriver 允許應用程序在多個 MySQL 主機之間進行負載平衡.使用 ReplicationDriver 時,JDBC URL 更改為 jdbc:mysql:replication://master-host[:master-port][,slave-1-host[:slave-1-port]][,slave-2-host[:slave-2-port]]/database.這允許應用程序連接到多個服務器之一,具體取決于在任何給定時間點可用的服務器.

                  Connector/J offers another driver called ReplicationDriver that allows an application to load-balance between multiple MySQL hosts. When using ReplicationDriver, the JDBC URL changes to jdbc:mysql:replication://master-host[:master-port][,slave-1-host[:slave-1-port]][,slave-2-host[:slave-2-port]]/database. This allows the application to connect to one of multiple servers depending on which one is available at any given point in time.

                  使用 ReplicationDriver 時,如果 JDBC 連接設置為 read-only,驅動程序會將 URL 中聲明的第一個主機視為 read-將 主機和所有其他主機寫入只讀 主機.開發人員可以通過如下構造他們的代碼在 Spring 應用程序中利用這一點:

                  When using the ReplicationDriver, if a JDBC connection is set to read-only, the driver treats the first host declared in the URL as a read-write host and all others as read-only hosts. Developers can take advantage of this in a Spring application by structuring their code as follows:

                  @Service
                  @Transactional(readOnly = true)
                  public class SomeServiceImpl implements SomeService {
                     public SomeDataType readSomething(...) { ... }
                  
                     @Transactional(readOnly = false)
                     public void writeSomething(...) { ... }
                  }
                  

                  這樣的代碼,每當readSomething方法被調用時,Spring事務管理代碼都會獲取一個JDBCConnection并調用setReadOnly(true)code> 在它上面,因為服務方法默認使用 @Transactional(readOnly = true) 注釋.這將使來自 readSomething 方法的所有數據庫查詢轉到非主 MySQL 主機之一,以循環方式進行負載平衡.同樣,每當writeSomething被調用時,Spring都會在底層的JDBCConnection上調用setReadOnly(false),強制數據庫查詢到master服務器.

                  With code like this, whenever the method readSomething is called, the Spring transaction management code will obtain a JDBC Connection and call setReadOnly(true) on it because the service methods are annotated with @Transactional(readOnly = true) by default. This will make all database queries from the readSomething method to go to one of the non-master MySQL hosts, load-balanced in a round-robin fashion. Similarly, whenever writeSomething is called, Spring will call setReadOnly(false) on the underlying JDBC Connection, forcing the database queries to go to the master server.

                  這種策略允許應用程序將所有只讀流量定向到一組 MySQL 服務器,將所有讀寫流量定向到不同的服務器,而無需更改應用程序的邏輯架構或開發人員不必擔心不同的數據庫主機和角色.

                  This strategy allows the application to direct all read-only traffic to one set of MySQL servers and all read-write traffic to a different server, without changing the application's logical architecture or the developers having to worry about different database hosts and roles.

                  這篇關于Spring/J2EE Apps 中的只讀和讀寫分離的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                  【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                  相關文檔推薦

                  How to use windowing functions efficiently to decide next N number of rows based on N number of previous values(如何有效地使用窗口函數根據 N 個先前值來決定接下來的 N 個行)
                  reuse the result of a select expression in the quot;GROUP BYquot; clause?(在“GROUP BY中重用選擇表達式的結果;條款?)
                  Does ignore option of Pyspark DataFrameWriter jdbc function ignore entire transaction or just offending rows?(Pyspark DataFrameWriter jdbc 函數的 ignore 選項是忽略整個事務還是只是有問題的行?) - IT屋-程序員軟件開發技
                  Error while using INSERT INTO table ON DUPLICATE KEY, using a for loop array(使用 INSERT INTO table ON DUPLICATE KEY 時出錯,使用 for 循環數組)
                  pyspark mysql jdbc load An error occurred while calling o23.load No suitable driver(pyspark mysql jdbc load 調用 o23.load 時發生錯誤 沒有合適的驅動程序)
                  How to integrate Apache Spark with MySQL for reading database tables as a spark dataframe?(如何將 Apache Spark 與 MySQL 集成以將數據庫表作為 Spark 數據幀讀取?)

                    <small id='vj6bB'></small><noframes id='vj6bB'>

                      <bdo id='vj6bB'></bdo><ul id='vj6bB'></ul>
                    • <legend id='vj6bB'><style id='vj6bB'><dir id='vj6bB'><q id='vj6bB'></q></dir></style></legend>

                            <tbody id='vj6bB'></tbody>

                            <i id='vj6bB'><tr id='vj6bB'><dt id='vj6bB'><q id='vj6bB'><span id='vj6bB'><b id='vj6bB'><form id='vj6bB'><ins id='vj6bB'></ins><ul id='vj6bB'></ul><sub id='vj6bB'></sub></form><legend id='vj6bB'></legend><bdo id='vj6bB'><pre id='vj6bB'><center id='vj6bB'></center></pre></bdo></b><th id='vj6bB'></th></span></q></dt></tr></i><div class="z5zxdbf" id='vj6bB'><tfoot id='vj6bB'></tfoot><dl id='vj6bB'><fieldset id='vj6bB'></fieldset></dl></div>
                            <tfoot id='vj6bB'></tfoot>
                            主站蜘蛛池模板: 牛奶检测仪-乳成分分析仪-北京海谊 | 食安观察网| 地脚螺栓_材质_标准-永年县德联地脚螺栓厂家 | 超声波清洗机_细胞破碎仪_实验室超声仪器_恒温水浴-广东洁盟深那仪器 | 服务器之家 - 专注于服务器技术及软件下载分享| 合肥防火门窗/隔断_合肥防火卷帘门厂家_安徽耐火窗_良万消防设备有限公司 | 锯边机,自动锯边机,双面涂胶机-建业顺达机械有限公司 | RS系列电阻器,RK_RJ启动调整电阻器,RQ_RZ电阻器-上海永上电器有限公司 | 除湿机|工业除湿机|抽湿器|大型地下室车间仓库吊顶防爆除湿机|抽湿烘干房|新风除湿机|调温/降温除湿机|恒温恒湿机|加湿机-杭州川田电器有限公司 | 顺景erp系统_erp软件_erp软件系统_企业erp管理系统-广东顺景软件科技有限公司 | 冲锋衣滑雪服厂家-冲锋衣定制工厂-滑雪服加工厂-广东睿牛户外(S-GERT) | Duoguan 夺冠集团| 油罐车_加油机_加油卷盘_加油机卷盘_罐车人孔盖_各类球阀_海底阀等车用配件厂家-湖北华特专用设备有限公司 | 钢托盘,铁托盘,钢制托盘,镀锌托盘,饲料托盘,钢托盘制造商-南京飞天金属13260753852 | 东莞猎头公司_深圳猎头公司_广州猎头公司-广东万诚猎头提供企业中高端人才招聘服务 | 杰福伦_磁致伸缩位移传感器_线性位移传感器-意大利GEFRAN杰福伦-河南赉威液压科技有限公司 | 成都租车_成都租车公司_成都租车网_众行宝| 综合管廊模具_生态,阶梯护坡模具_检查井模具制造-致宏模具厂家 | 活动策划,舞台搭建,活动策划公司-首选美湖上海活动策划公司 | 管理会计网-PCMA初级管理会计,中级管理会计考试网站 | 滚塑PE壳体-PE塑料浮球-警示PE浮筒-宁波君益塑业有限公司 | 飞扬动力官网-广告公司管理软件,广告公司管理系统,喷绘写真条幅制作管理软件,广告公司ERP系统 | 杭州网络公司_百度SEO优化-外贸网络推广_抖音小程序开发-杭州乐软科技有限公司 | 东莞市海宝机械有限公司-不锈钢分选机-硅胶橡胶-生活垃圾-涡电流-静电-金属-矿石分选机 | 广州云仓代发-昊哥云仓专业电商仓储托管外包代发货服务 | 华夏医界网_民营医疗产业信息平台_民营医院营销管理培训 | 上海小程序开发-上海小程序制作公司-上海网站建设-公众号开发运营-软件外包公司-咏熠科技 | 流程管理|流程管理软件|企业流程管理|微宏科技-AlphaFlow_流程管理系统软件服务商 | 【MBA备考网】-2024年工商管理硕士MBA院校/报考条件/培训/考试科目/提前面试/考试/学费-MBA备考网 | 数控走心机-走心机价格-双主轴走心机-宝宇百科 | 电脑知识|软件|系统|数据库|服务器|编程开发|网络运营|知识问答|技术教程文章 - 好吧啦网 | 防渗膜厂家|养殖防渗膜|水产养殖防渗膜-泰安佳路通工程材料有限公司 | 冷镦机-多工位冷镦机-高速冷镦机厂家-温州金诺机械设备制造有限公司 | 新能源汽车教学设备厂家报价[汽车教学设备运营18年]-恒信教具 | 右手官网|右手工业设计|外观设计公司|工业设计公司|产品创新设计|医疗产品结构设计|EMC产品结构设计 | 智慧养老_居家养老_社区养老_杰佳通 | 江西自考网-江西自学考试网| 石家庄救护车出租_重症转院_跨省跨境医疗转送_活动赛事医疗保障_康复出院_放弃治疗_腾康26年医疗护送转诊团队 | 不锈钢搅拌罐_高速搅拌罐厂家-无锡市凡格德化工装备科技有限公司 | 流量卡中心-流量卡套餐查询系统_移动电信联通流量卡套餐大全 | 99文库_实习生实用的范文资料文库站 |