Spring boot服务的注册与发现demo(一)
2017-03-23 11:27
543 查看
原文地址:http://www.maoyupeng.com/springboot-cloud-register-and-found.html
简单演示使用idea搭建Spring boot模块化项目结构搭建及Spring boot服务发现与注册 (该文章为作者笔记,只供参考,不要学习)
项目结构规划
假设我们这个项目有客户模块与管理员模块. 则项目结构划分为如上图:
修改后
修改后
由上图可知,在mpi-client-service(pom.xml)里面没有引入任何的依赖包,但是在Maven Dependencies 里面,则显示出了与父模块一样的引用依赖.
Spring-boot服务的注册与发现demo(二):http://www.maoyupeng.com/springboot-cloud-register-and-found-2.html
简单演示使用idea搭建Spring boot模块化项目结构搭建及Spring boot服务发现与注册 (该文章为作者笔记,只供参考,不要学习)
开发环境
操作系统 | Mac OS |
---|---|
JDK版本 | 1.8 |
Maven | 3.0.5 |
IDE | IntelliJ IDEA |
项目结构规划
项目结构规划
假设我们这个项目有客户模块与管理员模块. 则项目结构划分为如上图:
名称 | 描述 |
---|---|
mpicloud | 项目名称 |
mpi-admin-provide | 例: mpi项目下,管理员模块的提供方 |
mpi-admin-service | 例: mpi项目下,管理员模块的消费者 |
mpi-client-provide | mpi项目下,客户模块的提供方 |
mpi-client-service | mpi项目下,客户模块的消费者 |
mpi-cloud | 注册中心 (通俗的说法) |
新建父模块
步骤截图
配置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.maoyupeng.test</groupId> <artifactId>mpicloud</artifactId> <version>1.0-SNAPSHOT</version> </project>
修改后
<?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.maoyupeng.test</groupId> <artifactId>mpicloud</artifactId> <version>${mpicloid.version}</version> <!--修改打包方式为pom--> <packaging>pom</packaging> <!--项目名称--> <name>mpicloud</name> <!--项目描述--> <description>mpicloud for spring-boot</description> <!-- 子模块引入 --> <modules> </modules> <!-- 定义属性变量 使用方法例如: <version>${mpicloid.version}</version> 这样version里面的值为0.0.1-SNAPSHOT --> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <java.version>1.8</java.version> <!--main version--> <mpicloid.version>0.0.1-SNAPSHOT</mpicloid.version> <!--cloud服务jar版本--> <mpi-cloud.version>0.0.1-SNAPSHOT</mpi-cloud.version> <!--管理员服务jar版本--> <mpi-admin-service.version>0.0.1-SNAPSHOT</mpi-admin-service.version> <!--客户端服务jar版本--> <mpi-client-service.version>0.0.1-SNAPSHOT</mpi-client-service.version> <!--管理员提供方jar版本--> <mpi-admin-provide.version>0.0.1-SNAPSHOT</mpi-admin-provide.version> <!--客户端提供方jar版本--> <mpi-client-provide.version>0.0.1-SNAPSHOT</mpi-client-provide.version> </properties> <!--引入spring boot 核心包--> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.5.1.RELEASE</version> <relativePath/> <!-- lookup parent from repository --> </parent> <!--引入依赖包--> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> <dependency> <groupId>org.springframework.restdocs</groupId> <artifactId>spring-restdocs-mockmvc</artifactId> <scope>test</scope> </dependency> </dependencies> <!--插件--> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> <!--指定spring镜像仓库,有的时候依赖包会报错,如果引入了该仓库,就会解决问题--> <repositories> <repository> <id>spring-snapshots</id> <name>Spring Snapshots</name> <url>https://repo.spring.io/snapshot</url> <snapshots> <enabled>true</enabled> </snapshots> </repository> <repository> <id>spring-milestones</id> <name>Spring Milestones</name> <url>https://repo.spring.io/milestone</url> <snapshots> <enabled>false</enabled> </snapshots> </repository> </repositories> </project>
新建子模块
步骤截图
修改子模块(mpi-client-service)的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"> <parent> <artifactId>mpicloud</artifactId> <groupId>com.maoyupeng.test</groupId> <version>0.0.1-SNAPSHOT</version> </parent> <modelVersion>4.0.0</modelVersion> <artifactId>mpi-client-service</artifactId> </project>
修改后
<?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"> <parent> <artifactId>mpicloud</artifactId> <groupId>com.maoyupeng.test</groupId> <!--修改: 引用父模块中的properties, 引入成功,则配置生效--> <version>${mpicloid.version}</version> </parent> <modelVersion>4.0.0</modelVersion> <artifactId>mpi-client-service</artifactId> </project>
验证
由上图可知,在mpi-client-service(pom.xml)里面没有引入任何的依赖包,但是在Maven Dependencies 里面,则显示出了与父模块一样的引用依赖.
最后的项目结构
其他子模块的新建步骤雷同,所以省略…Spring-boot服务的注册与发现demo(二):http://www.maoyupeng.com/springboot-cloud-register-and-found-2.html
相关文章推荐
- Spring Cloud Spring Boot mybatis 企业分布式微服务云(二)服务注册与发现(Consul)
- Spring Boot + Spring Cloud 实现权限管理系统 后端篇(十八):服务注册和发现(Consul)
- Spring-Boot服务注册与发现
- Spring Cloud Spring Boot mybatis 企业分布式微服务云(一)服务注册与发现(Eureka)【Dalston版】
- SpringBoot -- 服务注册与发现
- SpringBoot+Springcloud+SpringBootAdmin 服务发现注册与服务监控完美整合
- SpringBoot ,zookeeper 服务的注册与发现
- spring boot(实现服务注册及发现)
- Spring Boot + Spring Cloud 构建微服务系统(一):服务注册和发现(Consul)
- Spring Cloud Spring Boot mybatis 企业分布式微服务云(二)服务注册与发现(Consul)
- Spring Cloud Spring Boot mybatis 企业分布式微服务云(一)服务注册与发现(Eureka)【Dalston版】
- 遗留非springboot传统项目接入eureka注册与服务发现
- 非springboot项目初始化服务注册发现和ribbon
- (二)SpringBoot+SpringCloud —— 使用Eureka实现服务注册与发现
- SpringBoot的服务注册与发现示例
- Spring cloud 实现服务注册及发现
- SpringCloud——Eureka服务注册和发现
- Spring Cloud 的Eureka服务注册与发现
- 使用Spring Cloud Consul实现服务的注册和发现
- Spring Cloud 学习之旅 --- 服务注册与发现(一)