看完這篇項目設計規約,你應該就能構建良好的項目工程結構了

{"type":"doc","content":[{"type":"heading","attrs":{"align":null,"level":1},"content":[{"type":"text","text":"應用分層","attrs":{}}]},{"type":"bulletedlist","content":[{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"默認上層依賴下層,箭頭關係表示直接依賴(比如開放接口可以依賴於Web層,也可以直接依賴於Service層)","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":1,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"開放接口層:","attrs":{}},{"type":"text","text":" 可以直接封裝Service方法暴露成RPC接口; 通過Web封裝成接口; 進行網關安全控制,流量控制等","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":1,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"終端顯示層:","attrs":{}},{"type":"text","text":" 各個端的模板渲染並執行顯示的層. 當前主要是velocity渲染,JS渲染,JSP渲染,移動端展示等","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":1,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"Web層:","attrs":{}},{"type":"text","text":" 主要對訪問控制進行轉發,各類基本參數校驗,或者不復用業務的簡單處理等","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":1,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"Service層:","attrs":{}},{"type":"text","text":" 相對具體的業務邏輯服務層","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":1,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"Manager層:","attrs":{}},{"type":"text","text":" 通用業務處理層,具有以下特徵:","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":2,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"對第三方平臺封裝的層,預處理返回結果及轉化異常信息","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":2,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"對Service層通用能力下沉,比如緩存方案,中間件通用處理","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":2,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"與DAO層交互,對多個DAO的組合複用","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":1,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"DAO層:","attrs":{}},{"type":"text","text":" 數據訪問層,與底層MySQL,Oracle,HBase等進行數據交互","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":1,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"外部接口或第三方平臺:","attrs":{}},{"type":"text","text":" 包括其它部門的RPC開放接口,基礎平臺,其它企業的HTTP接口","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":"none"},"content":[{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/15/150c1ea26d7b093f0266ebe8d7d67682.png","alt":null,"title":null,"style":null,"href":null,"fromPaste":false,"pastePass":false}}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"分層異常處理規約:","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":1,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"DAO層:","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":2,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"產生的異常類型有很多,無法用細粒度的異常進行catch","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":2,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"使用","attrs":{}},{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"catch(Exception e)","attrs":{}},{"type":"text","text":" 方式,並","attrs":{}},{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"throw new DAOException(e)","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":2,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"不需要打印日誌,因爲日誌在","attrs":{}},{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"Manager","attrs":{}},{"type":"text","text":"或者","attrs":{}},{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"Service","attrs":{}},{"type":"text","text":"層一定需要捕獲並打印到日誌文件中去,如果同臺服務器再打印日誌,會浪費性能和存儲","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":1,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"Service層:","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":2,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"出現異常時,必須記錄出錯日誌到磁盤,儘可能帶上參數信息,相當於保護案發現場","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":1,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"Manager層:","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":2,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"如果","attrs":{}},{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"Manager","attrs":{}},{"type":"text","text":"層與","attrs":{}},{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"Service","attrs":{}},{"type":"text","text":"同機部署,日誌方式與","attrs":{}},{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"DAO","attrs":{}},{"type":"text","text":"層處理一致","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":2,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"如果是單獨部署,採用與","attrs":{}},{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"Service","attrs":{}},{"type":"text","text":"一致的處理方式","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":1,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"Web層:","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":2,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"Web層絕對不允許繼續往上拋異常,因爲已經處於頂層","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":2,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"如果意識到這個異常將導致頁面無法正常渲染,應該直接跳轉到友好錯誤頁面,加上用戶容易理解的錯誤提示信息","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":1,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"開放接口層:","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":2,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"要將異常處理成錯誤碼和錯誤信息方式返回","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"分層領域模型規約:","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":1,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"DO:","attrs":{}},{"type":"text","text":" Data Object, 此對象與數據庫表結構一一對應,通過","attrs":{}},{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"DAO","attrs":{}},{"type":"text","text":"層向上傳輸數據源對象","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":1,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"DTO:","attrs":{}},{"type":"text","text":" Data Transfer Object, 數據傳輸對象 ","attrs":{}},{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":",Service","attrs":{}},{"type":"text","text":"或者","attrs":{}},{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"Manager","attrs":{}},{"type":"text","text":"向外傳輸的對象","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":1,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"BO:","attrs":{}},{"type":"text","text":" Business, 業務對象,由","attrs":{}},{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"Service","attrs":{}},{"type":"text","text":"層輸出的封裝業務邏輯對象","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":1,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"AO:","attrs":{}},{"type":"text","text":" Application Object, 應用對象,在","attrs":{}},{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"Web","attrs":{}},{"type":"text","text":"層與","attrs":{}},{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"Service","attrs":{}},{"type":"text","text":"層之間抽象的複用對象模型,極爲貼近展示層,複用度不高","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":1,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"VO:","attrs":{}},{"type":"text","text":" View Object, 顯示層對象,通常是","attrs":{}},{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"Web","attrs":{}},{"type":"text","text":"向模板渲染引擎層傳輸的對象","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":1,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"Query:","attrs":{}},{"type":"text","text":" 數據查詢對象,各層接收上層的查詢請求. 注意超過","attrs":{}},{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"2","attrs":{}},{"type":"text","text":"個參數的查詢封裝,禁止使用Map類來傳輸","attrs":{}}]}]}],"attrs":{}},{"type":"heading","attrs":{"align":null,"level":1},"content":[{"type":"text","text":"二方庫依賴規約","attrs":{}}]},{"type":"bulletedlist","content":[{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"定義GAV遵循以下規則:","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":1,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"GroupID格式: ","attrs":{}},{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"com.[公司/BU].業務線[.子業務線]","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":2,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"最多","attrs":{}},{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"4","attrs":{}},{"type":"text","text":"級","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":2,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"子業務線可選","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":2,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"com.taobao.jstorm, com.alibaba.dubbo.register","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":1,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"ArtifactID格式: ","attrs":{}},{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"產品線-模塊名","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":2,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"語義不重複不遺漏","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":2,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"先到中央倉庫查證一下","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":2,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"dubbo-client, fastjson-api","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":1,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"Version: ","attrs":{}},{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"主版本號.次版本號.修訂號","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":2,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"主版本號:","attrs":{}},{"type":"text","text":" 產品方向更改,或者大規模的API不兼容,或者架構不兼容升級","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":2,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"次版本號:","attrs":{}},{"type":"text","text":" 保持相對兼容性,增加主要功能特性,影響範圍極小的API不兼容修改","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":2,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"修訂號:","attrs":{}},{"type":"text","text":" 保持完全兼容性,修復BUG,新增次要功能特性","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":3,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"注意起始版本號爲: ","attrs":{}},{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"1.0.0","attrs":{}},{"type":"text","text":",而不是 ","attrs":{}},{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"0.0.1","attrs":{}},{"type":"text","text":".","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":3,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"正式發佈的類庫必須先去中央倉庫進行查證,使版本號有延續性,正式版本號不允許覆蓋升級","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"線上應用不要依賴","attrs":{}},{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"SNAPSHOT","attrs":{}},{"type":"text","text":"版本,除了安全包以外","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":1,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"不依賴SNAPSHOT版本是保證應用發佈的冪等性","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":1,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"同時也可以加快編譯時的打包構建","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"二方庫的新增或升級,保持除功能點之外的其它","attrs":{}},{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"jar","attrs":{}},{"type":"text","text":"包不變","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":1,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"如果有改變,必須明確評估和驗證,建議進行","attrs":{}},{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"dependency:resolve","attrs":{}},{"type":"text","text":"前後信息比對","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":1,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"如果仲裁結果完全不一致,那麼通過","attrs":{}},{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"dependency:tree","attrs":{}},{"type":"text","text":"命令,找出差異點,進行 ","attrs":{}},{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"< excludes >","attrs":{}},{"type":"text","text":" 排除jar包","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"二方庫可以定義枚舉類型,參數可以使用枚舉類型,但是接口返回值不允許使用枚舉類型或者包含枚舉類型的POJO對象","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"依賴於一個二方庫羣時,必須定義一個統一的版本變量,避免版本號不一致","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":1,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"依賴springframework-core, -context, -beans. 都是同一個版本號,可以定義一個變量來保存版本","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":1,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"${spring.version},","attrs":{}},{"type":"text","text":" 定義依賴的時候,引用該版本","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"禁止在子項目的","attrs":{}},{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"pom","attrs":{}},{"type":"text","text":"依賴中出現相同的","attrs":{}},{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"GroupId,","attrs":{}},{"type":"text","text":" 相同的","attrs":{}},{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"ArtifactId,","attrs":{}},{"type":"text","text":" 但是不同的","attrs":{}},{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"Version","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":1,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"在本地調試時會使用各子項目指定的版本號,但是合併成一個","attrs":{}},{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"war,","attrs":{}},{"type":"text","text":" 只能有一個版本號出現在","attrs":{}},{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"lib","attrs":{}},{"type":"text","text":"目錄中","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":1,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"可能出現線下調試是正確的,發佈到線上去出現故障問題","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"所以","attrs":{}},{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"pom","attrs":{}},{"type":"text","text":"文件中的依賴聲明放在 ","attrs":{}},{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"< dependencies >","attrs":{}},{"type":"text","text":" 語句塊中,所有版本號仲裁放在 ","attrs":{}},{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"< dependencyManagement >","attrs":{}},{"type":"text","text":" 語句塊中","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":1,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"< dependencyManagement >","attrs":{}},{"type":"text","text":" 裏只是聲明版本,並不實現引入","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":1,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"需要子項目顯式的聲明依賴 ","attrs":{}},{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":",version","attrs":{}},{"type":"text","text":"和","attrs":{}},{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"scope","attrs":{}},{"type":"text","text":"都讀取自父","attrs":{}},{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"pom","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":1,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"< dependencies >","attrs":{}},{"type":"text","text":" 所有聲明在主","attrs":{}},{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"pom","attrs":{}},{"type":"text","text":"的 ","attrs":{}},{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"< dependencies >","attrs":{}},{"type":"text","text":" 裏的依賴都會自動導入,並默認被所有的子項目繼承","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"二方庫不要有配置項,最低限度不要再增加配置項","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"爲了避免應用二方庫的依賴衝突問題,二方庫發佈者應當遵循以下原則:","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":1,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"精簡可控原則:","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":2,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"移除一切不必要的","attrs":{}},{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"API","attrs":{}},{"type":"text","text":"和依賴,只包含","attrs":{}},{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"Service API,","attrs":{}},{"type":"text","text":" 必要的領域模型對象, Utils類, 常量, 枚舉等","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":2,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"如果依賴其它二方庫,儘量是","attrs":{}},{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"provided","attrs":{}},{"type":"text","text":"引入,讓二方庫使用者去依賴具體的版本號","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":2,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"無","attrs":{}},{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"log","attrs":{}},{"type":"text","text":"的具體實現,只依賴日誌框架","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":1,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"穩定可追溯原則:","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":2,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"每個版本的變化應該被記錄,二方庫維護信息,源碼位置,都需要能夠方便查到","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":2,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"除非用戶主動升級版本,否則公共二方庫的行爲不應該發生變化","attrs":{}}]}]}],"attrs":{}},{"type":"heading","attrs":{"align":null,"level":1},"content":[{"type":"text","text":"服務器規約","attrs":{}}]},{"type":"bulletedlist","content":[{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"高併發的服務器要調小","attrs":{}},{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"TCP","attrs":{}},{"type":"text","text":"協議的","attrs":{}},{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"time_wait","attrs":{}},{"type":"text","text":"時間","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":1,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"操作系統默認","attrs":{}},{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"240","attrs":{}},{"type":"text","text":"秒後,纔會關閉處於","attrs":{}},{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"time_wait","attrs":{}},{"type":"text","text":"狀態的連接","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":1,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"在高併發訪問下,服務器端會因爲處於","attrs":{}},{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"time_wait","attrs":{}},{"type":"text","text":"的連接數太多,可能無法建立新的連接","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":1,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"所以需要在服務器上調小此等待值","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":2,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"在linux服務器上通過變更 ","attrs":{}},{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"/etc/sysctl.conf","attrs":{}},{"type":"text","text":"文件去修改該缺省值(s)","attrs":{}}]}]}],"attrs":{}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"codeblock","attrs":{"lang":"powershell"},"content":[{"type":"text","text":"net.ipv4.tcp_fin_timeout = 30\n","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"bulletedlist","content":[{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"調大服務器所支持的最大文件句柄數(fd, File Descriptor)","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":1,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"主流操作系統的設計是將","attrs":{}},{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"TCP/UDP","attrs":{}},{"type":"text","text":"連接採用與文件一樣的方式去管理,即一個連接對應於一個","attrs":{}},{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"fd","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":1,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"主流的","attrs":{}},{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"linux","attrs":{}},{"type":"text","text":"服務器默認支持的最大","attrs":{}},{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"fd","attrs":{}},{"type":"text","text":"數量爲","attrs":{}},{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"1024,","attrs":{}},{"type":"text","text":" 當併發連接數很大時很容易因爲","attrs":{}},{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"fd","attrs":{}},{"type":"text","text":"不足出現 ","attrs":{}},{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"\"open too many files\"","attrs":{}},{"type":"text","text":" 錯誤,導致新的連接無法建立","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":1,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"需要將","attrs":{}},{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"linux","attrs":{}},{"type":"text","text":"服務器支持的最大句柄數調高數倍,與服務器內存數量相關","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"給","attrs":{}},{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"JVM","attrs":{}},{"type":"text","text":"環境參數設置 ","attrs":{}},{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"-XX: +HeapDumpOnOutOfMemoryError","attrs":{}},{"type":"text","text":" 參數,使JVM遇到OOM場景時輸出","attrs":{}},{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"dump","attrs":{}},{"type":"text","text":"信息","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":1,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"OOM","attrs":{}},{"type":"text","text":"的發生是有概率的,甚至相隔數月纔出現一例,出錯時的堆內信息對解決問題非常有幫助","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"在線上生產環境 ","attrs":{}},{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":",JVM","attrs":{}},{"type":"text","text":"的","attrs":{}},{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"Xms","attrs":{}},{"type":"text","text":"和","attrs":{}},{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"Xmx","attrs":{}},{"type":"text","text":"設置一樣大小的內存容量,避免在","attrs":{}},{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"GC","attrs":{}},{"type":"text","text":"後調整堆大小帶來的壓力","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"服務器重定向","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":1,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"服務器內部重定向使用","attrs":{}},{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"forward","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":1,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"服務器外部重定向地址使用","attrs":{}},{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"URL","attrs":{}},{"type":"text","text":"拼裝工具類來生成,否則會帶來URL維護不一致問題和潛在的安全風險","attrs":{}}]}]}],"attrs":{}}]}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章