1.说明

本文详解介绍Spring Cloud项目的父工程创建,
由于Spring Cloud项目下有很多模块组件,
需要先创建一个大的父工程项目,
然后在下面创建各个子工程模块。

2.创建父工程

这一步创建一个Maven Project,
作为Spring Cloud的父工程:
File -> New -> Other... -> Maven -> Maven Project

勾选Create a simple project(skip archetype selection),
然后去掉勾选Use default Workspace location,
点击Browse...设置自己项目保存的Location:
D:\Code\Learn\SpringCloud\spring-cloud-demo

点击Next下一步,
这里输入要创建的项目的名称等信息,
主要是修改Group Id,Artifact Id,Packaging,
注意Packaging设置为pom,
表示该项目是作为父工程使用,
顺便一提子工程建立的Packaging应该为jar。

点击Finish完成工程创建。

3.查看pom.xml

<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.yuwen.spring</groupId>
<artifactId>spring-cloud-demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<description>Spring Cloud Demo Project</description>
</project>

4.删除多余的目录

删除父工程下的src目录,
因为父工程没有源码文件。

5.添加依赖

在pom.xml中的dependencyManagement下面,
加入Spring Boot和Spring Cloud依赖管理,
注意这里的Spring Boot和Spring Cloud版本要匹配:

<dependencyManagement>
<dependencies>
<!--spring boot dependencies-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>2.3.1.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<!--spring cloud dependencies-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Hoxton.SR6</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

这样子模块继承之后,
在子模块中就不用写依赖的版本号,
各个子模块就不会有jar包冲突问题了。

6.添加构建

在pom.xml中的build下面,
加入spring-boot-maven-plugin打包插件,
指定了使用Maven打包Spring Boot工程时,
goal为repackage即重新打包,
重新打出的新jar包就会有正确的启动类。
子工程打包时,会继承该打包配置,
否则子工程使用mvn clean install打包后,
会发生jar包找不到main无法运行问题。

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.3.1.RELEASE</version>
<executions>
<execution>
<!--打包时,重新打包指定spring boot的启动类 -->
<id>repackage</id>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

7.父工程的parent说明

由于这里的父工程没有它的parent父工程,
也可以使用spring-boot-starter-parent作为父工程,
可以解决上一步的打包问题。

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.1.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>

但是如果这里的父工程需要继承公司更高一级的父工程,
那这种方法就无法使用了,
而且这种方法没有上一步的通用。
推荐开发遇到问题时,
把spring-boot-starter-parent作为参考,
而不是直接依赖其作为父工程。

8.Spring Cloud和Spring Boot版本对应关系

"spring-cloud": {
"Finchley.M2": "Spring Boot >=2.0.0.M3 and <2.0.0.M5",
"Finchley.M3": "Spring Boot >=2.0.0.M5 and <=2.0.0.M5",
"Finchley.M4": "Spring Boot >=2.0.0.M6 and <=2.0.0.M6",
"Finchley.M5": "Spring Boot >=2.0.0.M7 and <=2.0.0.M7",
"Finchley.M6": "Spring Boot >=2.0.0.RC1 and <=2.0.0.RC1",
"Finchley.M7": "Spring Boot >=2.0.0.RC2 and <=2.0.0.RC2",
"Finchley.M9": "Spring Boot >=2.0.0.RELEASE and <=2.0.0.RELEASE",
"Finchley.RC1": "Spring Boot >=2.0.1.RELEASE and <2.0.2.RELEASE",
"Finchley.RC2": "Spring Boot >=2.0.2.RELEASE and <2.0.3.RELEASE",
"Finchley.SR4": "Spring Boot >=2.0.3.RELEASE and <2.0.999.BUILD-SNAPSHOT",
"Finchley.BUILD-SNAPSHOT": "Spring Boot >=2.0.999.BUILD-SNAPSHOT and <2.1.0.M3",
"Greenwich.M1": "Spring Boot >=2.1.0.M3 and <2.1.0.RELEASE",
"Greenwich.SR6": "Spring Boot >=2.1.0.RELEASE and <2.1.16.BUILD-SNAPSHOT",
"Greenwich.BUILD-SNAPSHOT": "Spring Boot >=2.1.16.BUILD-SNAPSHOT and <2.2.0.M4",
"Hoxton.SR6": "Spring Boot >=2.2.0.M4 and <2.3.2.BUILD-SNAPSHOT",
"Hoxton.BUILD-SNAPSHOT": "Spring Boot >=2.3.2.BUILD-SNAPSHOT and <2.4.0.M1",
"2020.0.0-SNAPSHOT": "Spring Boot >=2.4.0.M1"
}
注意两者一定要匹配,
不然会发生意想不到的问题,
而且比较难处理的。
最新的对应关系查询地址:
https://start.spring.io/actuator/info

SpringCloud创建项目父工程的更多相关文章

  1. springboot 创建子父工程

    1.创建子父工程 2.添加pom配置文件 2.1  父工程pom.xml <project xmlns="http://maven.apache.org/POM/4.0.0" ...

  2. Spring cloud系列教程第二篇:支付项目父工程图文搭建

    Spring cloud系列教程第二篇:支付项目父工程图文搭建 在讲解spring cloud相关的技术的时候,咱们就模拟订单支付这个流程来讲讲 在这个支付模块微服务搭建过程中,上面的这些技术,都会融 ...

  3. App开发流程之创建项目和工程基本配置

    我的开发环境为:Mac OS X EI Capitan(10.11.6),Xcode 7.3.1 首先说明一下这个项目的初衷,我并非要创建一个完整的上架应用,旨在创建一个可运行的,通用配置.架构,提供 ...

  4. Keil的使用-1创建项目和工程

    下载keil,注意不要使用MDK版本(主要是arm开发使用),大小约54M 安装过程不再详述 安装Keil成功并运行后,新建项目,   创建新项目,然后弹出下图,选择对应的单片机芯片(双击)     ...

  5. SpringCloud创建Config模块

    1.说明 本文详细介绍Spring Cloud创建Config模块的方法, 基于已经创建好的Spring Cloud父工程, 请参考SpringCloud创建项目父工程, 创建Config模块这个子工 ...

  6. SpringCloud创建Gateway模块

    1.说明 本文详细介绍Spring Cloud创建Gateway模块的方法, 基于已经创建好的Spring Cloud父工程, 请参考SpringCloud创建项目父工程, 和已经创建好的Eureka ...

  7. SpringCloud创建Eureka模块

    1.说明 本文详细介绍Spring Cloud创建Eureka模块的方法, 基于已经创建好的Spring Cloud父工程, 请参考SpringCloud创建项目父工程, 在里面创建Eureka模块, ...

  8. maven(二) maven项目构建ssh工程(父工程与子模块的拆分与聚合)

    前一节我们明白了maven是个什么玩意,这一节就来讲讲他的一个重要的应用场景,也就是通过maven将一个ssh项目分割为不同的几个部分独立开发,很重要,加油 --WH 一.maven父工程与子模块的拆 ...

  9. 使用IntelliJ IDEA创建Maven聚合工程、创建resources文件夹、ssm框架整合、项目运行一体化

    一.创建一个空的项目作为存放整个项目的路径 1.选择 File——>new——>Project ——>Empty Project 2.WorkspaceforTest为项目存放文件夹 ...

随机推荐

  1. vue引入d3

    单页面使用 cnpm install d3 --save-dev 指定版本安装 cnpm install d3@6.3.1 -S <script> import * as d3 from ...

  2. ligerUI 关闭父弹窗JS报错问题 解决方法

    1:调用父窗口某一个文件框,获取焦点, parent.window.document.getElementById("roleName").focus(); 2:关闭父窗口pare ...

  3. 『学了就忘』Linux系统管理 — 83、Linux中进程的查看(top命令)

    目录 1.top命令介绍 2.top命令示例 3.top命令输出项解释 4.top命令常用的实例 1.top命令介绍 top命令是用来动态显示系统中进程的命令. [root@localhost ~]# ...

  4. mysql优化大全(转自别人 )

    文章出处:https://blog.csdn.net/weixin_38112233/article/details/79054661 数据库优化 sql语句优化 索引优化 加缓存 读写分离 分区 分 ...

  5. HTTP强缓存和协商缓存

    一.浏览器缓存 Web 缓存能够减少延迟与网络阻塞,进而减少显示某个资源所用的时间.借助 HTTP 缓存,Web 站点变得更具有响应性. (一).缓存优点: 减少不必要的数据传输,节省带宽 减少服务器 ...

  6. C# 使用163的SMTP服务器发送邮件

    string Receiver, string Subject, string content: //163邮箱发送配置 client = new System.Net.Mail.SmtpClient ...

  7. 解决Tensorflow ValueError: Failed to convert a NumPy array to a Tensor (Unsupported object type numpy.ndarray)

    问题描述 在将一个数组送入tensorflow训练时,报错如下: ValueError: Failed to convert a NumPy array to a Tensor (Unsupporte ...

  8. CF17A Noldbach problem 题解

    Content 若一个素数可以用比它小的相邻的两个素数的和加 \(1\) 表示,那么称这个素数为"好素数". 给定两个正整数 \(n,k\),问从 \(2\) 到 \(n\) 的好 ...

  9. SpringCloud (一) Eureka

    Eureka Eureka 是一个服务治理组件,它主要包括服务注册和服务发现,主要用来搭建服务注册中心. Eureka 是一个基于 REST 的服务,用来定位服务,进行中间层服务器的负载均衡和故障转移 ...

  10. mysql数据库总结笔记

    一.安装和配置数据库: 下载mysql地址:https://dev.mysql.com/downloads/mysql/ windows下载的版本是installer msi版本:https://de ...