您的位置:首页 > 编程语言 > Java开发

spring-cloud 学习一 介绍

2016-11-08 00:00 309 查看
  微服务Microservice,跟之相对应的是将功能从开发到交付都打包成一个很大的服务单元,一般称之为Monolith,也称「巨石」架构。微服务实现和实施思路更强调功能单一,服务单元小型化和微型化,倡导将服务粒度做小,使它可以独立承担对外服务的职责。

  Spring Cloud是一个基于Spring Boot实现的云应用开发工具,它为基于JVM的云应用开发中的配置管理、服务发现、断路器、智能路由、微代理、控制总线、全局锁、决策竞选、分布式会话和集群状态管理等操作提供了一种简单的开发方式。

  接下来会以一个简单的demo来学习Spring Cloud ,地址在github,demo使用maven构建。

  包含几个子module

  server-discovery:服务发现

  config-service:配置服务

  user-provider-service:服务提供者

  user-ui: 消费者,web前端展示

  api-gateway: 服务网关

首先配置hosts,操作都以域名访问 127.0.0.1 discovery config gateway

demo中的代码参考(抄袭)自 https://github.com/kbastani/spring-cloud-microservice-examplehttp://blog.didispace.com/springcloud5/ 以及http://git.oschina.net/itmuch/spring-cloud-study

创建父级项目 spring-cloud-demo,pom文件内容

<?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.dh.cloud</groupId>
<artifactId>spring-cloud-demo</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>

<modules>
<module>server-discovery</module>
<module>user-provider-service</module>
<module>user-ui</module>
<module>api-gateway</module>
<module>config-service</module>
</modules>

<parent>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-parent</artifactId>
<version>Camden.SR1</version>
<relativePath/>
<!-- lookup parent from repository -->
</parent>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
<docker.plugin.version>0.4.11</docker.plugin.version>
</properties>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-parent</artifactId>
<version>Camden.SR1</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

<repositories>
<repository>
<id>spring-snapshots</id>
<name>Spring Snapshots</name>
<url>http://repo.spring.io/libs-snapshot-local</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
<repository>
<id>spring-snapshots-continuous</id>
<name>Spring Snapshots Continuous</name>
<url>http://repo.spring.io/libs-snapshot-continuous-local</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
<repository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>http://repo.spring.io/libs-milestone-local</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
<repository>
<id>spring-releases</id>
<name>Spring Releases</name>
<url>http://repo.spring.io/libs-release-local</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>spring-snapshots</id>
<name>Spring Snapshots</name>
<url>http://repo.spring.io/libs-snapshot-local</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
<pluginRepository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>http://repo.spring.io/libs-milestone-local</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</project>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: