主要内容
1. 项目构建思想
项目具体的构建思想是底层技术和业务低耦合。具体是将微服务依赖的服务中心和业务逻辑分为两个工程创建。微服务依赖主要包括配置中心,集群式服务注册中心,服务监控,服务跟踪模块等。业务实现使用其他工程创建,具体也是使用模块化,此处的模块化是将控制器,业务逻辑,数据映射分为三个模块。这里主要是介绍一下项目的思想。文中使用的代码不是全部的构建代码。
2. 微服务父级工程配置
微服务每个工程模块均依赖一个父级可以减少很多版本不匹配造成的困扰。在父级pom中指定使用的SpringBoot和SpringCloud版本。
如下:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.4.RELEASE</version>
</parent>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Camden.SR5</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
项目依赖的公共jar包可以放到<dependencies>
中,这里我们主要使用springboot-starter构建基于springboot的应用。如下:
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
之后我们构建模块时就不必引入上述依赖。中管理了springcloud版本,当我们使用springcloud的模块的时候不必指定版本号。
END
之后会依次介绍如何构建服务配置中心,服务注册中心等模块。