Spring Cloud第二篇 创建一个Eureka Server
来源:互联网 发布:淘宝店铺氛围图是什么 编辑:程序博客网 时间:2024/06/05 11:34
在Spring Cloud实现一个Eureka Server是一件非常简单的事情。下面我们来写一个Eureka Server DEMO。
编码
(1) 首先创建一个Maven工程,添加内容如下:
<?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.itmuch.cloud</groupId> <artifactId>microservice-discovery-eureka</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>jar</packaging> <!-- 引入spring boot的依赖 --> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.4.1.RELEASE</version> </parent> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <java.version>1.8</java.version> </properties> <dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-eureka-server</artifactId> </dependency> </dependencies> <!-- 引入spring cloud的依赖 --> <dependencyManagement> <dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-dependencies</artifactId> <version>Camden.SR1</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement> <!-- 添加spring-boot的maven插件 --> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build></project>
(2) 编写启动类,在启动类上添加@EnableEurekaServer 注解。
@SpringBootApplication@EnableEurekaServerpublic class EurekaApplication { public static void main(String[] args) { SpringApplication.run(EurekaApplication.class, args); }}
(3) 编写配置文件application.yml
server: port: 8761eureka: client: registerWithEureka: false fetchRegistry: false serviceUrl: defaultZone: http://localhost:8761/eureka/
这样就完成了一个简单的Eureka Server。简要说明一下application.yml中的配置项:
eureka.client.registerWithEureka :表示是否将自己注册到Eureka Server,默认为true。由于当前这个应用就是Eureka Server,故而设为false。
eureka.client.fetchRegistry :表示是否从Eureka Server获取注册信息,默认为true。因为这是一个单点的Eureka Server,不需要同步其他的Eureka Server节点的数据,故而设为false。
eureka.client.serviceUrl.defaultZone :设置与Eureka Server交互的地址,查询服务和注册服务都需要依赖这个地址。默认是http://localhost:8761/eureka ;多个地址可使用 , 分隔。
Eureka的配置类所在类:
org.springframework.cloud.netflix.eureka.EurekaInstanceConfigBeanorg.springframework.cloud.netflix.eureka.EurekaClientConfigBeanorg.springframework.cloud.netflix.eureka.server.EurekaServerConfigBean
测试
启动工程后,访问:http://localhost:8761/ 。我们会发现此时还没有服务注册到Eureka上面,如下图:
eureka
该页面展示了Eureka的系统状态、当前注册到Eureka Server上的服务实例、一般信息、实例信息等。我们可以看到,当前还没有任何服务被注册到Eureka Server上。
- Spring Cloud第二篇 创建一个Eureka Server
- MAC 用 Intellij Idea 创建 Spring Cloud Eureka Server 例子
- spring cloud 之eureka-server
- spring cloud eureka server HA
- spring cloud eureka server 配置
- spring cloud eureka-server搭建
- spring cloud中启动Eureka Server
- Spring Cloud Eureka Server HA With Docker
- spring cloud之Eureka Server环境搭建
- spring cloud eureka server warning EUREKA MAY BE INCORRECTLY
- Spring-Cloud系列第2篇:spring-cloud-eureka
- Spring-Cloud系列第3篇:spring-cloud-eureka-consumer
- spring cloud-eureka
- Spring-cloud Eureka 集群
- spring cloud eureka
- Spring Cloud Eureka
- Spring Cloud Netflix Eureka
- Spring Cloud Eureka详解
- 每天一个linux命令(37):date命令
- codility MaxDoubleSliceSum
- cvGet2D和cvGetReal2D
- 217. Contains Duplicate
- Python3.5--列表之深copy与浅copy、元组(下)
- Spring Cloud第二篇 创建一个Eureka Server
- angular2 markdown parser
- 无边框input
- centos服务器 禁止普通用户重启关机
- HTTP返回代码 201 304 404 500等代表的含义
- 机器学习——对三种模式的看法
- art-template的使用
- iOS Crash 捕获及堆栈符号化思路剖析
- jedis和redis主从集成和遇到的问题