Spring Cloud微服务(一)

什么是Spring Cloud

简单来说,Spring Cloud是一个微服务框架的规范,注意,只是规范,他不是任何具体的框架。Spring Cloud 为最常见的分布式系统模式提供了一种简单且易于接受的编程模型,帮助开发人员构建有弹性的、可靠的、协调的应用程序。Spring Cloud 构建于 Spring Boot 之上,使得开发者很容易入手并快速应用于生产中。

新建Spring Cloud项目

选择Eureka server就可以新建eureka注册中心了。

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>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.4.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.spc</groupId>
<artifactId>eurekaserver</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>eurekaserver</name>
<description>Demo project for Spring Boot</description> <properties>
<java.version>1.8</java.version>
<spring-cloud.version>Greenwich.SR1</spring-cloud.version>
</properties> <dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency> <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies> <dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement> <build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build> </project>

使用 @EnableEurekaServer 来说明项目是一个 Eureka

@SpringBootApplication
@EnableEurekaServer
public class EurekaServerApplication { public static void main(String[] args) {
SpringApplication.run(EurekaServerApplication.class, args);
}
}

修改配置文件

server:
  port: 8761

eureka:
  instance:
    hostname: localhost
  client:
    registerWithEureka: false
    fetchRegistry: false
    serviceUrl:
      defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/

运行 EurekaServerApplication 类,启动项目,访问项目 http://localhost:8761/

最新文章

  1. 网站实现微信登录之回调函数中登录逻辑的处理--基于yii2开发的描述
  2. UICollectionView中使用 UICollectionViewFlowLayout进行布局(模仿苹果相册)
  3. VC 使用OnCtlColor函数来改变控件颜色(引用)
  4. jdbc基础 (二) 通过properties配置文件连接数据库
  5. View绑定式监听器实现原理
  6. 黄聪:jquery mobile使用form进行post提交表单没有反应,显示空白页解决方案
  7. ORA-15005: name &quot;orcl&quot; is already used by an existing alias
  8. java中的定时器
  9. BAE 环境下配置 struts2 + spring + hibernate(SSH)(二)struts2
  10. MB_CHANGE_DOCUMENT使用方法
  11. X-007 FriendlyARM tiny4412 u-boot移植之内存初始化
  12. php设计模式七 ---组合模式
  13. 乾坤合一~Linux设备驱动之块设备驱动
  14. Fragment+FragmentActivity出现The specified child already has a parent. You must call removeView() on the child&#39;s parent first.
  15. Codeforces 891C Envy
  16. (笔记)Mysql命令show databases:显示所有数据库
  17. Python 程序员都会喜欢的 6 个库
  18. arcgis license manager 10.2服务无法启动
  19. hdu-1141
  20. &#39;org.springframework.web.filter.CharacterEncodingFilter&#39; is not assignable to &#39;javax.servlet.Filter,This inspection lets you spot the following problems that might occur in descriptors that are used t

热门文章

  1. crtmpserver服务器的搭建
  2. redis---&gt;事务和锁
  3. docker扫盲,面试连这都不会就等着挂吧!
  4. Linux 6种日志查看方法,不会看日志会被鄙视的
  5. SpringBoot+MyBatis项目Dao层最简单写法
  6. 深入理解JDK中的Reference原理和源码实现
  7. java数据域初始化
  8. Android Studio 学习笔记(一)环境搭建、文件目录等相关说明
  9. c++ 内存分配中一个有趣的小问题
  10. Python socket 基础(Server) - Foundations of Python Socket