網站首頁 編程語言 正文
文章目錄
- 多模塊構建維護
- 一、聚合
- 二、繼承
- 三、聚合與繼承
- 四、屬性
- 4.1 介紹
- 4.2 常見的屬性及其調用方式
- 1、自定義屬性
- 2、內置屬性
- 3、setting屬性
- 4、java系統屬性
- 5、環境變量屬性
多模塊構建維護
可以看到通過上一章的講解,我們將一個ssm項目分模塊管理,形成了pojo、dao、service、controller四個模塊,并且逐層遞進形成依賴關系,假設此時dao層模塊出現了改動,我們該如何進一步管理呢?
一、聚合
聚合用于快速構建maven工程,一次性構建多個項目、模塊
操作起來很簡單:
- 創建一個空模塊,打包類型定義為pom
- 定義當前模塊進行構建操作時關聯其他的模塊(綁定)
注:參與合操作的模塊最終執行順序與模塊間的依賴關系有關,與配置順序無關
首先構建一個maven的項目,只留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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.zyx</groupId>
<artifactId>maven_ssm</artifactId>
<version>1.0-SNAPSHOT</version>
<!-- 定義該工程用于構建項目管理 -->
<packaging>pom</packaging>
<!-- 管理的工程列表 -->
<modules>
<!-- 具體的工程 -->
<module>../maven_ssm_pojo</module>
<module>../maven_ssm_dao</module>
<module>../maven_ssm_service</module>
<module>../maven_ssm_controller</module>
</modules>
</project>
對項目進行整體的編譯,可以看到結果顯示的是所有的模塊選項:
install一下:
可以看到對應的文件夾下添加了jar包文件:
返回頂部
二、繼承
模塊間依賴關系的維護
實際開發過程中,由于每個模塊一個負責人,所以會導致每個人使用的相同依賴出現不同版本,可能會引發版本沖突問題。
如上圖所示,假設service、dao模塊都用到了spring-context依賴,但是一個5.1.9,另一個5.2.0,就有可能引起版本的問題。此時我們可以通過繼承實現子工程中沿用父工程(ssm)的配置,統一版本。
首先在父工程中聲明其子工程的所需要的所有坐標,并配置聲明依賴管理:
<!--聲明此處進行依賴管理-->
<dependencyManagement>
<!--具體的依賴-->
<dependencies>
<!--添加自己的工程模塊依賴-->
<dependency>
<groupId>com.zyx</groupId>
<artifactId>maven_ssm_pojo</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.zyx</groupId>
<artifactId>maven_ssm_dao</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.zyx</groupId>
<artifactId>maven_ssm_service</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<!--spring環境-->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>5.1.9.RELEASE</version>
</dependency>
<!--mybatis環境-->
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>3.5.3</version>
</dependency>
<!--mysql環境-->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.47</version>
</dependency>
<!--spring整合jdbc-->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>5.1.9.RELEASE</version>
</dependency>
<!--spring整合mybatis-->
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-spring</artifactId>
<version>2.0.3</version>
</dependency>
<!--druid連接池-->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>1.1.16</version>
</dependency>
<!--分頁插件坐標-->
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper</artifactId>
<version>5.1.2</version>
</dependency>
<!-- spring mvc環境 -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>5.1.9.RELEASE</version>
</dependency>
<!--jackson相關坐標3個-->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.9.0</version>
</dependency>
<!--servlet環境-->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<scope>provided</scope>
</dependency>
<!--其他組件-->
<!--junit單元測試-->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
</dependency>
<!--spring整合junit-->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>5.1.9.RELEASE</version>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<pluginManagement>
<!--設置插件-->
<plugins>
<!--具體的插件配置-->
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.1</version>
<configuration>
<port>80</port>
<path>/</path>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
子工程中對應聲明使用父工程的依賴配置,同時將子工程所有的版本信息去除:
<!--定義該工程的父工程-->
<parent>
<groupId>com.zyx</groupId>
<artifactId>maven_ssm</artifactId>
<version>1.0-SNAPSHOT</version>
<!--填寫父工程的pom文件-->
<relativePath>../maven_ssm/pom.xml</relativePath>
</parent>
<dependencies>
<!--spring -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
</dependency>
</dependencies>
可繼承的資源:
返回頂部
三、聚合與繼承
作用
- 聚合用于快速構建項目
- 繼承用于快速配置
相同點
- 聚合與繼承的pom.xm文件打包方式均為pom,可以將兩種關系制作到同一個pom文件中
- 聚合與繼承均屬于設計型模塊,并無實際的模塊內容
不同點
- 聚合是在當前模塊中配置關系,聚合可以感知到參與聚合的模塊有哪些
- 繼承是在子模塊中配置關系,父模塊無法感知哪些子模塊繼承了自己
返回頂部
四、屬性
4.1 介紹
版本統一的重要性
雖然我們可以在父項目中進行依賴資源的統一管理,但是不免我們有時會出錯,如上圖所示,上下配置的資源版本不一致,這種情況下我們可以增添屬性信息避免人為配置的出錯。
<!--定義自定義屬性-->
<properties>
<spring.version>5.1.9.RELEASE</spring.version>
<junit.version>4.12</junit.version>
</properties>
<!--聲明此處進行依賴管理-->
<dependencyManagement>
<!--具體的依賴-->
<dependencies>
<!--其他組件-->
<!--junit單元測試-->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
</dependency>
<!--spring整合junit-->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>${spring.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
對于我們繼承的項目依賴,版本同樣可以統一,因為使用的是maven的項目對象版本,在最開始就聲明了<version>1.0-SNAPSHOT</version>
,所以后面直接使用${version}
調用就行了。
<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.itheima</groupId>
<artifactId>ssm</artifactId>
<version>1.0-SNAPSHOT</version>
<!-- 定義該工程用于構建項目管理 -->
<packaging>pom</packaging>
<!--聲明此處進行依賴管理-->
<dependencyManagement>
<!--具體的依賴-->
<dependencies>
<!--添加自己的工程模塊依賴-->
<dependency>
<groupId>com.itheima</groupId>
<artifactId>ssm_pojo</artifactId>
<version>${version}</version>
</dependency>
<dependency>
<groupId>com.itheima</groupId>
<artifactId>ssm_dao</artifactId>
<version>${version}</version>
</dependency>
<dependency>
<groupId>com.itheima</groupId>
<artifactId>ssm_service</artifactId>
<version>${version}</version>
</dependency>
</dependencies>
</dependencyManagement>
返回頂部
4.2 常見的屬性及其調用方式
1、自定義屬性
2、內置屬性
3、setting屬性
4、java系統屬性
5、環境變量屬性
返回頂部
原文鏈接:https://blog.csdn.net/qq_45797116/article/details/125783265
相關推薦
- 2022-06-19 rsa詳解及例題及python算法_python
- 2022-07-30 if-else和switch的練習及區別比較
- 2022-04-02 詳解Android如何自定義view實現圓形進度條_Android
- 2022-07-08 C#中的Dialog對話框_C#教程
- 2022-12-09 Android入門之ProgressBar的使用教程_Android
- 2022-08-14 Redis+Caffeine兩級緩存的實現_Redis
- 2022-05-14 .NetCore?Web?Api?利用ActionFilterAttribute統一接口返回值格式及
- 2022-05-24 awk腳本統計一組單詞中字母出現最多最少頻率_linux shell
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支