微服务的设计原则:
1、单一职责原则 一个微服务只干一件事
2、服务自治原则 每个微服务应该能做到独立开发、测试、部署、维护,不需要其他模块的参与
3、轻量级通讯原则 最好能够通过http请求在服务之间进行互相的调用
4、接口明确原则 微服务之间进行访问、调用都是通过接口的方式进行调用,尽量避免在一个微服务
中包含其他微服务的内容
微服务版本对应关系
使用spring cloud做微服务的大体结构
开发步骤:
创建项目为maven项目,我的jdk版本是jdk1.8,因此需要改动一下maven配置文件,将jdk版本改为jdk1.8,不然建立的项目为jdk1.5版本如图
修改:maven下的setting.xml文件
在200行左右找到如下位置,改为:
复制代码块粘贴进去
<profile>
<id>jdk-1.8</id>
<activation>
<activeByDefault>true</activeByDefault>
<jdk>1.8</jdk>
</activation>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>
</properties>
</profile>
创建项目:
①创建父工程
②:在父工程导入依赖
<dependencyManagement>
<dependencies>
<!-- spring cloud -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Greenwich.SR1</version>
<type>pom</type>
<scope>runtime</scope>
</dependency>
<!-- spring boot -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>2.1.0.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<!-- mysql -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.44</version>
</dependency>
<!-- druid -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>1.1.15</version>
</dependency>
<!-- mybatis -->
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>1.3.2</version>
</dependency>
<!-- junit -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version