)
一、分模块设计与开发为什么将一个大项目拆分成若干个子模块方便项目的管理维护、扩展也方便模块间的相互引用资源共享。策略一按照功能模块拆分比如公共组件、商品模块、搜索模块、购物车模块、订单模块等。策略二按层拆分比如公共组件、实体类、控制层、业务层、数据访问层。策略三按照功能模块层拆分。1、实战创建新工程web-ai-project03配置SDK检查Maven目录将tlias-web-management项目复制到该模块下项目结构导入pom.xml创建新模块在模块中将pojo包下的所有文件复制过来src下路径要保持一致将lombok和org.springframework.boot依赖加入将tlias项目的pojo包删掉导入tlias-pojo的包后即可使用dependency groupIdcom.itheima/groupId artifactIdtlias-pojo/artifactId version1.0-SNAPSHOT/version /dependency创建tlias-utils模块同上根据依赖传递可以直接把依赖剪切过去3、小结1.什么是分模块设计?将项目按照功能模块/层拆分成若干个子模块2为什么要分模块设计?方便项目的管理维护、扩展也方便模块间的相互引用资源共享3.注意事项分模块设计需要先针对模块功能进行设计再进行编码。不会先将工程开发完毕然后进行拆分二、继承1、继承关系1介绍概念继承描述的是两个工程间的关系与java中的继承相似子工程可以继承父工程中的配置信息常见于依赖关系的继承。作用简化依赖配置、统一管理依赖实现parent.../parent2实现创建maven模块tlias-parent该工程为父工程设置打包方式pom(默认jar)。在子工程的pom.xml文件中配置继承关系。在父工程中配置各个工程共有的依赖子工程会自动继承父工程的依赖。打包方式jar普通模块打包springboot项目基本都是jar包内嵌tomcat运行war普通web程序打包需要部署在外部的tomcat服务器中运行pom父工程或聚合工程该模块不写代码仅进行依赖管理a、创建父工程创建模块tlias-parent只留一个pom.xml文件即可parent !-- 坐标信息-- groupIdorg.springframework.boot/groupId artifactIdspring-boot-starter-parent/artifactId version3.2.10/version !-- 父工程的pom.xml的相对路径-- !-- 未指定会在本地仓库查找该依赖没有就在中央仓库查找该依赖-- relativePath/ !-- lookup parent from repository -- /parent groupIdcom.itheima/groupId artifactIdtlias-parent/artifactId version1.0-SNAPSHOT/version packagingpom/packagingb、配置继承关系tlias-pojo、tlias-utils、tlias-web-management中父工程和子工程的groupId相同子工程可以省略!-- 父工程-- parent groupIdcom.itheima/groupId artifactIdtlias-parent/artifactId version1.0-SNAPSHOT/version relativePath../tlias-parent/pom.xml/relativePath /parent !--groupIdcom.itheima/groupId-- artifactIdtlias-utils/artifactId version1.0-SNAPSHOT/versionc、父工程配置共有依赖加入dependency即可子工程可以删除2、版本锁定在maven中可以在父工程的pom文件中通过dependencyManagement来统一管理依赖版本。1统一管理版本!-- 统一管理依赖的版本 -- dependencyManagement dependencies !--阿里云OSS依赖-- dependency groupIdcom.aliyun.oss/groupId artifactIdaliyun-sdk-oss/artifactId version3.17.4/version /dependency dependency groupIdjavax.xml.bind/groupId artifactIdjaxb-api/artifactId version2.3.1/version /dependency dependency groupIdjavax.activation/groupId artifactIdactivation/artifactId version1.1.1/version /dependency !-- no more than 2.3.3-- dependency groupIdorg.glassfish.jaxb/groupId artifactIdjaxb-runtime/artifactId version2.3.3/version /dependency !--JWT-- dependency groupIdio.jsonwebtoken/groupId artifactIdjjwt/artifactId version0.9.1/version /dependency /dependencies /dependencyManagement子工程的版本直接删掉即可2自定义属性/引用属性properties maven.compiler.source17/maven.compiler.source maven.compiler.target17/maven.compiler.target project.build.sourceEncodingUTF-8/project.build.sourceEncoding !--自定义属性-- lombok.version1.18.34/lombok.version spring.boot.starter.version3.2.10/spring.boot.starter.version aliyun.sdk.version3.17.4/aliyun.sdk.version jaxb.api.version2.3.1/jaxb.api.version activation.version1.1.1/activation.version jaxb.runtime2.3.3/jaxb.runtime jjwt.version0.9.1/jjwt.version /properties引用版本version${spring.boot.starter.version}/version三、聚合主项目在生命周期的打包操作时需要将其他项模块进行生命周期的install安装到本地目录聚合将多个模块组织成一个整体同时进行项目的构建。聚合工程和父工程是一个工程聚合工程一个不具有业务功能的“空”工程有且仅有一个pom文件作用快速构建项目无需根据依赖关系手动构建直接在聚合工程上构建即可实现maven中可以通过modules设置当前聚合工程所包含的子模块名称!--聚合哪些模块-- modules module../tlias-pojo/module module../tlias-utils/module module../tlias-web-management/module /modules只需要点父工程生命周期的package打包即可1maven中如何实现聚合关系modules.../modules2maven中继承与聚合的联系与区别联系继承与聚合都属于设计型模块打包方式都为pom常将两种关系制作到同一个pom文件中区别1继承用于简化依赖配置、统一管理依赖版本是在子工程中配置继承关系2聚合用于快速构建项目是在父工程聚合工程中配置聚合的模块四、私服1、介绍私服是一种特殊的远程仓库它是架设在局域网内的仓库服务用来代理位于外部的中央仓库用于解决团队内部的资源共享与资源同步问题。依赖查找顺序本地仓库私服中央仓库注意私服在企业项目开发中一个项目/公司只需要一台即可无需我们自已搭建会使用即可。2、资源上传与下载项目版本central中央仓库RELEASE发行版本功能趋于稳定、当前更新停止可以用于发行的版本存储在私服中的RELEASE仓库中。SNAPSHOT快照版本功能不稳定、尚处于开发中的版本即快照版本存储在私服的SNAPSHOT仓库中。找到该文件双击启动私服D:\install\installpath\nexus\nexus-3.75.1-01\bin\start.bat出现Started Sonatype Nexus OSS 3.75.1-01代表启动成功访问localhost:8081配置Maven的私服属性找到路径D:\install\envresoce\apache-maven-3.9.4\conf\settings.xml配置releases仓库和snapshots仓库的用户名和密码/servers server idmaven-releases/id usernameadmin/username passwordadmin/password /server server idmaven-snapshots/id usernameadmin/username passwordadmin/password /server /servers配置私服地址mirrors mirror idmaven-public/id mirrorOf*/mirrorOf urlhttp://localhost:8081/repository/maven-public/url /mirror /mirrors启用快照版本和发行版本访问profiles profile idallow-snapshots/id activation activeByDefaulttrue/activeByDefault /activation repositories repository idmaven-public/id urlhttp://localhost:8081/repository/maven-public//url releases enabledtrue/enabled /releases snapshots enabledtrue/enabled /snapshots /repository /repositories /profile /profiles在父工程的pom.xml的结尾配置版本的上传地址distributionManagement !-- release版本的发布地址 -- repository idmaven-releases/id urlhttp://localhost:8081/repository/maven-releases//url /repository !-- snapshot版本的发布地址 -- snapshotRepository idmaven-snapshots/id urlhttp://localhost:8081/repository/maven-snapshots//url /snapshotRepository /distributionManagement若pom文件中版本不带snapshots就代表是release版本在其他工程中直接会在本地仓库查找接着就去私服查找了dependency groupIdcom.itheima/groupId artifactIdtlias-utils/artifactId version1.0-SNAPSHOT/version /dependency私服用完要把setting.xml里加的注释掉不然要一直开着这个私服五、Web开发-总结Spring MVC是Spring Framework的一部分。是Spring对于web框架开发的支持