点击查看: Spring Cloud实战教程
父项目
父项目只需要 保留 这些文件, 其他的 删除:
子模块 (方式一[Maven
]: 推荐)
子模块 (方式二[Spring Initializr
])
点击查看: Spring Cloud 和 Spring Boot 版本对应
推荐版本:
Spring Cloud
: Hoxton.SR8 (最常用的版本)Spring Cloud Alibaba
: 2.2.5.RELEASESpring Boot
: 2.3.2.RELEASE
所有版本关系:
8 8 UTF-8 Hoxton.SR8 2.2.5.RELEASE 8.0.26 3.5.2 1.2.14 1.2.1 1.2.71 1.0.4 2.6 3.2.2 2.6
Springcloud-实现跨项目相互调用 (简易版: 不使用Feign版本)
点击查看: Maven项目命名规范 (groupID、artifactid)
: 定义当前 Maven项目 隶属的 实际项目,例如
com.compang.project
。
- 前半部分
com.compang
: 代表此项目隶属的 公司。- 后半部分
project
: 代表 项目的名称。- 例如: 腾讯(tencent) 的 微信(wechat)项目:
com.tencent.wechat
。
: 构件ID, 该元素定义实际项目中的一个 Maven项目 或者是 子模块
- 构建名 称必须 小写字母,没有其他的 特殊字符。
- 父项目: 【公司名-项目名】,例如:
tencent-wechat
。- 子模块: 【
公司名-项目名-模块名
】,例如:tencent-wechat-user
、tencent-wechat-file。
> - 子模块方案二: 【项目名-模块名
】,例如:wechat-user
、wechat-file。
父模块
com.tencent.wechat
tencent-wechat
pom
1.0-SNAPSHOT
子模块
com.tencent.wechat tencent-wechat 1.0-SNAPSHOT
tencent-wechat-user
点击查看: Spring Cloud 中 dependencyManagement、type、scope在 父模块 和 子模块 的作用?
- 在 父项目 中使用
dependencyManagement
,继承该 父项目 的 子项目 默认不会直接引入 dependencyManagement 管理的 jar包。- 子项目 要继承 父项目 的 依赖 时, 需要 显式的声明 需要用的 依赖,并且不指定 version,才会从 父项目 中继承该 依赖,这时
version
和scope
都读取自父pom
;
org.springframework.cloud spring-cloud-dependencies ${spring-cloud.version} pom import
4.0.0 org.springframework.boot spring-boot-starter-parent 2.3.2.RELEASE com.tencent.wechat tencent-wechat 0.0.1-SNAPSHOT pom tencent-wechat-user tencent-wechat-blog tencent-wechat-common 8 8 UTF-8 Hoxton.SR8 2.2.5.RELEASE 8.0.26 3.5.2 1.2.14 1.2.1 1.2.71 1.0.4 2.6 3.2.2 2.6 org.springframework.cloud spring-cloud-dependencies ${spring-cloud.version} pom import
mysql mysql-connector-java ${mysql.version} com.baomidou mybatis-plus ${mybatis-plus.version} com.alibaba druid-spring-boot-starter ${druid.version}
com.github.penggle kaptcha ${kaptcha.version} com.aliyun.oss aliyun-sdk-oss 3.8.0 com.alibaba fastjson ${fastjson.version} com.arronlong httpclientutil ${httpclientutil.version} commons-lang commons-lang ${commons-lang.version} commons-collections commons-collections ${commons-collections.version} commons-io commons-io ${commons-io.version} org.projectlombok lombok true 1.18.20 junit junit 4.13.2 test org.slf4j slf4j-jdk14 1.5.6
4.0.0 com.tencent.wechat tencent-wechat 0.0.1-SNAPSHOT tencent-wechat-user 1.8 8 8 UTF-8 com.tencent.wechat tencent-wechat-common 0.0.1-SNAPSHOT
org.springframework.boot spring-boot-starter-test test org.springframework.boot spring-boot-devtools com.baomidou mybatis-plus-core 3.5.2 compile org.projectlombok lombok
com.github.yulichang mybatis-plus-join 1.3.8 org.springframework.boot spring-boot-maven-plugin
server:port: 8190servlet:context-path: /user #上下文请求路径,请求前缀 ip:port/user
spring:application:name: user-server #应用名#数据库配置datasource:url: jdbc:mysql://xxx.xxx.xxx.xxx:3306/xxx?zeroDateTimeBehavior=convertToNull&useUnicode=true&characterEncoding=utf8&serverTimezone=GMT%2B8&autoReconnect=true&nullCatalogMeansCurrent=true&allowMultiQueries=trueusername: xxxpassword: xxxdriver-class-name: com.mysql.cj.jdbc.Driver
mybatis-plus:type-aliases-package: com.tencent.wechat.user.entitiesmapper-locations: classpath*:com/tencent/wechat/user/mapper/**/*.xmlconfiguration:map-underscore-to-camel-case: false
logging:level:com.pkpmgl.pt.deptuser.mapper: debug
公用模块包含的 依赖: (一般引入 依赖的启动器)
spring-boot-starter-web
mysql-connector-java
mybatis-plus-boot-starter
druid-spring-boot-starter
mybatis-plus-join
mybatis-plus-join-core
- …
4.0.0 com.tencent.wechat tencent-wechat 0.0.1-SNAPSHOT tencent-wechat-common 1.8 org.springframework.boot spring-boot-starter-web
org.springframework.boot spring-boot-starter-validation com.baomidou mybatis-plus-boot-starter 3.5.2 com.alibaba druid-spring-boot-starter mysql mysql-connector-java runtime org.springframework.boot spring-boot-configuration-processor true org.projectlombok lombok com.spring4all swagger-spring-boot-starter 1.9.1.RELEASE
com.alibaba fastjson com.arronlong httpclientutil commons-lang commons-lang commons-collections commons-collections commons-io commons-io com.github.yulichang mybatis-plus-join-core 1.3.8 compile com.github.yulichang mybatis-plus-join 1.3.8 org.springframework.boot spring-boot-maven-plugin