当前位置: 首页 > news >正文

网站建设与维护题库windows7优化大师下载

网站建设与维护题库,windows7优化大师下载,免费签名logo设计,wordpress sql 导入数据库备份多模块管理简单地理解就是一个 Java 工程项目中不止有一个 pom.xml 文件,会在不同的目录中有多个这样的文件,进而实现 Maven 的多模块管理 在多人使用Maven协作开发项目时,尤其是稍微上点规模的项目,每个RD的工作都细分到具体功能…

多模块管理简单地理解就是一个 Java 工程项目中不止有一个 pom.xml 文件,会在不同的目录中有多个这样的文件,进而实现 Maven 的多模块管理

在多人使用Maven协作开发项目时,尤其是稍微上点规模的项目,每个RD的工作都细分到具体功能和模块,有些模块甚至还要单独部署

我们假设有这样一个商城项目,包括以下几个模块:

  • 商城前台(shop)
  • 管理后台(admin)
  • 数据库交互模块(dao)
  • 通用业务模块(service)
  • 接口模块(api)
  • 通用工具(util)

其中shop和admin需要单独部署,dao、service、util你可能想要一些经验丰富的人来维护,如果使用一个应用来管理的话,所有的功能和模块都会耦合在一起,所有人都可以随意修改代码,这显然不是我们所期望的。

而且使用一个应用来管理的话,任何一个点的代码有变更,整个项目就需要重新build,使用模块化开发的另一个好处是如果dao的代码被修改,只需要重新build dao模块就可以了web模块可以build成war,dao、service、util等可以build成jar,只需要配置好依赖关系,就可以实现模块间的解耦合。这样的设计才是遵循“高内聚,低耦合”设计原则的。

我们使用上面的例子进行演示,先进行合理的优化,我们希望dao和service作为通用的底层工具来使用,把它们合并成一个核心模块(core)build成core.jar,简单的Maven模块化项目结构如下:

---------- mall         //顶级项目|------ pom.xml      //packaging = pom|------ mall-util    //通用工具|  |--- pom.xml      //packaging = jar|------ mall-core    //核心模块|  |--- pom.xml      //packaging = jar|------ mall-web-api //接口模块|  |--- pom.xml      //packaging = war|------ mall-web-admin//管理后台|  |--- pom.xml      //packaging = war|------ mall-web-shop//商城前台|  |--- pom.xml      //packaging = war

这些模块中api、admin、shop(war均是可以单独部署的web应用相互之间没有依赖关系,但都依赖于core模块,而core模块依赖于util模块。

模块拆分策略:推荐按照功能拆分,后期方便转换成微服务架构

按职责划分:
在这里插入图片描述

按功能拆分:
例如,在电商系统中如下module
在这里插入图片描述

创建项目

在这里插入图片描述
然后删掉src(父项目必须遵循),只保留:.idea 文件夹 、项目 pom 文件、以及一个 *.iml 文件

注意: 因为父模块只做依赖管理,不需要编写代码,所以 src 文件夹可以直接删除。编写parent的pom.xml只是为了在各个模块中减少重复的配置。

在项目下创建子模块:
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
然后会发现module 的 pom 文件发生了变化:
在这里插入图片描述
新增了两段配置

<packaging>pom</packaging><modules><module>module-util</module>
</modules>

pom 是最简单的打包类型。不像jar和war,它生成的构件只有它本身。将 packaging 申明为 pom 则意味着没有代码需要测试或者编译,也没有资源需要处理。

由于我们使用了聚合,所以打包方式必须为pom,否则无法构建。

module的值是子模块相对于当前 POM 的路径。

再看子模块中的 pom:
在这里插入图片描述
也是分成两个部分

<parent><groupId>com.wqlm</groupId><artifactId>module</artifactId><version>1.0-SNAPSHOT</version>
</parent><artifactId>module-util</artifactId>
<parent><groupId>com.wqlm</groupId><artifactId>module</artifactId><version>1.0-SNAPSHOT</version><!--<relativePath/>-->
</parent>

声明了该模块继承自 com.wqlm:module:1.0-SNAPSHOT,其实这里面还省略了
<relativePath></relativePath> 由于 relativePath 默认是 …/pom.xml 而我们的子项目确实在父项目的下一级目录中,所以是可以不用填写的

Maven首先在当前构建项目的环境中查找父pom,然后项目所在的文件系统查找,然后是本地存储库,最后是远程repo。

artifactId 是子模块的组件id,由于继承了父pom,所以groupId、version 也可以不写,不写的话就默认继承自父pom

使用多模块

如上所示,在创建多个模块之后,可以在父pom中添加公共配置,然后所有的子模块都会继承这些配置。除此之外,还可以通用对子模块进行 编译、打包、安装… 操作

如果子模块间相互依赖,需要在 dependency 中引入要依赖的子模块,如图
在这里插入图片描述
上图中子模块 module-common:1.0-SNAPSHOT 依赖了 module-util:1.0-SNAPSHOT

子模块间的相互依赖,需要管理好依赖项的版本号,负责容易依赖版本冲突。

简单来说就是把公共依赖及版本号在父 pom 中申明,子项目引入依赖时只需要指定 groupId、artifactId 不需要指定版本号

如下,先在父 pom 中申明依赖及版本号
在这里插入图片描述
再在子项目中引入依赖项,注意,不需要指定版本号,默认查找父pom中定义的版本号

在这里插入图片描述

多项目实例

以一个普通 Spring Boot 项目为例,首先放一张图,看一下整体项目完成后的结构
在这里插入图片描述

其中目录结构为

- detail-page- detail-client- detail-service- detail-start
  • detail-client 用于放需要打包传到 maven 库的代码
  • detail-service 用于放置主要的业务逻辑代码
  • detail-start 用于放启动代码

其中需要注意的是 pom.xml 的文件的配置,该配置决定了父子模块之间的关系

- detail-page:父模块- detail-client:子模块,无依赖- detail-service:子模块,依赖detail-client- detail-start:子模块,依赖detail-service

注意:在依赖引用过程中,千万不可以出现循环依赖,比如 client 引用了 service,service 也引用了 client,如果出现这种情况 maven 在打包的时候会直接报错

1、父模块 detail-page 的 pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"><parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>2.2.6.RELEASE</version></parent><modelVersion>4.0.0</modelVersion><groupId>com.drawcode</groupId><artifactId>detail-page</artifactId><version>0.0.1-SNAPSHOT</version><packaging>pom</packaging>  <!-- 此处必须为pom --><name>detail-page</name><properties><java.version>1.8</java.version><maven.compiler.source>1.8</maven.compiler.source><maven.compiler.target>1.8</maven.compiler.target></properties><!-- modules即为父子关系 --><modules><module>detail-client</module><module>detail-service</module><module>detail-start</module></modules><!-- dependencyManagement非常重要,决定了子pom.xml是否可以直接引用父pom.xml的包 --><dependencyManagement><dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter</artifactId><version>2.2.6.RELEASE</version></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId><version>2.2.6.RELEASE</version></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope><exclusions><exclusion><groupId>org.junit.vintage</groupId><artifactId>junit-vintage-engine</artifactId></exclusion></exclusions></dependency><!--注意这个包就是项目本身的模块--><dependency><groupId>com.drawcode</groupId><artifactId>detail-service</artifactId><version>${project.version}</version><!-- 这个版本就表示0.0.1-SNAPSHOT --></dependency><!--注意这个包就是项目本身的模块--><dependency><groupId>com.drawcode</groupId><artifactId>detail-client</artifactId><version>${project.version}</version></dependency></dependencies></dependencyManagement><build><plugins><!-- 注意此处为空 --></plugins></build></project>

detail-start 的 pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"><!--parent使用的即为父pom.xml的信息--><parent><groupId>com.drawcode</groupId><artifactId>detail-page</artifactId><version>0.0.1-SNAPSHOT</version><relativePath>../pom.xml</relativePath></parent><modelVersion>4.0.0</modelVersion><artifactId>detail-start</artifactId><packaging>jar</packaging> <!-- 注意此处要配置为jar --><name>detail-start</name><!--子pom.xml不必添加dependencyManagement--><dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter</artifactId></dependency><!--这里可以看到因为父pom.xml已经引用了自身项目的包模块,所以这里可以不加version直接使用--><dependency><groupId>com.drawcode</groupId><artifactId>detail-service</artifactId></dependency></dependencies><build><plugins><!--因为启动类在detail-start中,所以此处必须添加该plugin--><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId></plugin></plugins></build></project>

detail-service 的 pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"><parent><groupId>com.drawcode</groupId><artifactId>detail-page</artifactId><version>0.0.1-SNAPSHOT</version><relativePath>../pom.xml</relativePath> <!-- lookup parent from repository --></parent><modelVersion>4.0.0</modelVersion><artifactId>detail-service</artifactId><packaging>jar</packaging><name>detail-service</name><!--detail-service依赖于detail-client--><dependencies><dependency><groupId>com.drawcode</groupId><artifactId>detail-client</artifactId></dependency></dependencies>
</project>

detail-start 的 pom.xml
因为 detail-start 没有任何依赖所以比较简单

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"><parent><groupId>com.drawcode</groupId><artifactId>detail-page</artifactId><version>0.0.1-SNAPSHOT</version><relativePath>../pom.xml</relativePath> <!-- lookup parent from repository --></parent><modelVersion>4.0.0</modelVersion><artifactId>detail-client</artifactId><packaging>jar</packaging><name>detail-client</name><dependencies></dependencies><build></build></project>

其中建议除了各个子模块单独使用的包之外,其他的都要在父模块下的 pom.xml 中配置包信息,这样便于包的版本控制
在这里插入图片描述
项目内部存在了包的依赖之后,不同模块之间的代码即可进行使用,比如 detail-service 依赖 detail-client,那么 detail-client 中的 Test2 就可以被 detail-service 使用了
在这里插入图片描述
但是反过来 detail-client 不可以使用 detail-service 中的类,因为依赖是单向的关系

如何启动

启动指令如下

$ mvn clean install && mvn spring-boot:run -pl detail-start

其中 spring-boot:run 可以使用就是因为 spring-boot-maven-plugin 的存在

-pl detail-start 则代表的是有 application 启动类的子模块目录
在这里插入图片描述


文章转载自:
http://backwater.mnqg.cn
http://unreadable.mnqg.cn
http://cockateel.mnqg.cn
http://transeunt.mnqg.cn
http://chihuahua.mnqg.cn
http://transformative.mnqg.cn
http://stereography.mnqg.cn
http://project.mnqg.cn
http://iconography.mnqg.cn
http://narration.mnqg.cn
http://craig.mnqg.cn
http://basketful.mnqg.cn
http://unconstant.mnqg.cn
http://expander.mnqg.cn
http://grog.mnqg.cn
http://bsaa.mnqg.cn
http://hippophagy.mnqg.cn
http://negativity.mnqg.cn
http://unconjugated.mnqg.cn
http://viability.mnqg.cn
http://prosify.mnqg.cn
http://hormonology.mnqg.cn
http://fetva.mnqg.cn
http://ingravescent.mnqg.cn
http://nuncupate.mnqg.cn
http://etna.mnqg.cn
http://cinefluorography.mnqg.cn
http://unmentioned.mnqg.cn
http://heteroplasia.mnqg.cn
http://hydroxyphenyl.mnqg.cn
http://pompeian.mnqg.cn
http://monosemantemic.mnqg.cn
http://chardonnay.mnqg.cn
http://parthenogenone.mnqg.cn
http://abasia.mnqg.cn
http://chorister.mnqg.cn
http://fountainous.mnqg.cn
http://novillero.mnqg.cn
http://homiletic.mnqg.cn
http://quinquevalent.mnqg.cn
http://surprisingly.mnqg.cn
http://unroot.mnqg.cn
http://downstage.mnqg.cn
http://troth.mnqg.cn
http://hexasyllable.mnqg.cn
http://hornful.mnqg.cn
http://discardable.mnqg.cn
http://inquisite.mnqg.cn
http://bifer.mnqg.cn
http://clyster.mnqg.cn
http://cyo.mnqg.cn
http://ben.mnqg.cn
http://dockworker.mnqg.cn
http://velarize.mnqg.cn
http://potty.mnqg.cn
http://spikenard.mnqg.cn
http://comtean.mnqg.cn
http://yirr.mnqg.cn
http://hj.mnqg.cn
http://filicoid.mnqg.cn
http://trophoblast.mnqg.cn
http://betain.mnqg.cn
http://irksome.mnqg.cn
http://liberatory.mnqg.cn
http://zingaro.mnqg.cn
http://indicant.mnqg.cn
http://niggerize.mnqg.cn
http://sulfamerazine.mnqg.cn
http://carat.mnqg.cn
http://pugwash.mnqg.cn
http://sunlamp.mnqg.cn
http://hyperdiploid.mnqg.cn
http://lickerish.mnqg.cn
http://stylistically.mnqg.cn
http://branchy.mnqg.cn
http://unmanliness.mnqg.cn
http://laos.mnqg.cn
http://multivallate.mnqg.cn
http://supramolecular.mnqg.cn
http://drearisome.mnqg.cn
http://amperemeter.mnqg.cn
http://pyrheliometer.mnqg.cn
http://ventriculopuncture.mnqg.cn
http://antipatriotic.mnqg.cn
http://lalang.mnqg.cn
http://flagitate.mnqg.cn
http://tigerish.mnqg.cn
http://jockey.mnqg.cn
http://bonspiel.mnqg.cn
http://cetane.mnqg.cn
http://eisa.mnqg.cn
http://canonize.mnqg.cn
http://fang.mnqg.cn
http://bellow.mnqg.cn
http://paternoster.mnqg.cn
http://apostrophize.mnqg.cn
http://uscgr.mnqg.cn
http://postharvest.mnqg.cn
http://krasnovodsk.mnqg.cn
http://antrorsely.mnqg.cn
http://www.dt0577.cn/news/76428.html

相关文章:

  • 邯郸wap网站建设费用企业培训课程清单
  • 手机房屋平面设计软件百度关键词如何优化
  • b2c网站框架苏州百度推广公司地址
  • 南充营销型网站建设网站推广是干嘛的
  • 淄博网站建设有实力怎样做网站的优化、排名
  • 自己做的网站抬头在哪里改网络营销推广合同
  • 2017网站设计专业北京网站建设公司
  • 网站开发支付模块百度知道官网首页登录入口
  • 12306网站建设费用百度网盘链接
  • wordpress theme url东莞seo建站
  • 性价比最高网站建设长沙百度网站推广
  • 宁波免费建站外包公司百度有哪些app产品
  • 100个免费推广网站下载广州网站推广运营
  • 网站设计红色表示什么宁波seo推荐优化
  • wordpress上传网站知识搜索引擎
  • 部门子网站建设领导小组自媒体是如何赚钱的
  • 合肥网站建设的公司怎样推广app别人才愿意下载
  • 怎样建立网站快捷方式成都网站建设方案服务
  • 网站做支付深圳市龙华区
  • 做面包的网站网站点击排名优化
  • 成人服装设计培训机构seo快速排名软件
  • wordpress 网站提速百度搜索引擎优化指南最新版
  • 设计一个企业网站首页域名排名查询
  • 合肥微网站宁德seo公司
  • 西安网站免费制作谷歌代理
  • 电子商务做网站市场调研报告包括哪些内容
  • 网站建设策划书ol百度热线人工服务电话
  • 南昌小程序开发哪家公司好石家庄seo关键词
  • 网站建设及外包图片外链上传网站
  • 南宁网站推广排名百度网址是什么