分布式系統架構
互聯網企業的業務飛速發展,促使系統架構不斷變化。總體來說,系統架構大致經歷了單體應用架構—垂直應用架構—分布式架構—SOA架構—微服務架構的演變,很多互聯網企業的系統架構已經向服務化網格(Service Mesh)演變。
單體應用架構:所有的模塊寫到一個Web項目中,再統一部署到一個Web服務器中。
分布式架構:將重復的代碼抽象出來,形成統一的服務,供其他系統或者業務模塊調用。
xxx-common: pojo,utils,config
xxx-system: pojo,dao,service
xxx-admin : controller
system 調用公共模塊 common,控制模塊 admin 調用業務模塊 system。
簡單舉例。
創建項目
父級配置
<!--修改父級打包方式-->
<packaging>pom</packaging>
<!--子級都有誰-->
<modules><module>boot-admin</module><module>boot-common</module><module>boot-system</module>
</modules>
子級配置
<!--修改子級打包方式-->
<packaging>jar</packaging>
<!--引入父級-->
<parent><groupId>com.hz</groupId><artifactId>boot-parent</artifactId><version>0.0.1-SNAPSHOT</version>
</parent>
三者的依賴關系
<!-- boot-system -->
<dependencies><dependency><groupId>com.hz</groupId><artifactId>boot-common</artifactId><version>0.0.1-SNAPSHOT</version></dependency>
</dependencies>
<!-- boot-admin -->
<dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><dependency><groupId>com.hz</groupId><artifactId>boot-system</artifactId><version>0.0.1-SNAPSHOT</version></dependency>
</dependencies>
<!-- boot-parent -->
<!-- 在 boot-parent 中引入需要的依賴 這樣所有的子級都可以使用 -->
<dependencies><dependency><groupId>com.mysql</groupId><artifactId>mysql-connector-j</artifactId><scope>runtime</scope></dependency><dependency><groupId>com.baomidou</groupId><artifactId>mybatis-plus-boot-starter</artifactId><version>3.5.1</version></dependency><dependency><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope></dependency>
</dependencies>
boot-common
模塊結構:公共實體類、工具類等
boot-system
模塊結構:數據持久化、服務接口及其實現類等
boot-admin
模塊結構:啟動類、控制器、yml配置文件等
打開 Maven,點擊父級 boot-parent
打包
去到該目錄下
D:\idea_workspaces\boot-parent\boot-admin\target
打開終端,輸入命令
>java -jar boot-admin-0.0.1-SNAPSHOT-smbms.jar
運行項目
成功運行后調用接口測試,成功即可。