看完这篇项目设计规约,你应该就能构建良好的项目工程结构了

{"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":{}}]}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章