【微服务架构 - 08 - Spring Cloud】02 服务注册与发现
pom.xml
其 pom.xml
文件配置:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency>
Application
启动一个服务注册中心,只需要一个注解 @EnableEurekaServer
package com.yuu.hello.spring.cloud.eureka;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;
/**
* @Classname EurekaApplication
* @Date 2019/1/28 21:12
* @Created by Yuu
*/
@SpringBootApplication
@EnableEurekaServer
public class EurekaApplication {
public static void main(String[] args) {
SpringApplication.run(EurekaApplication.class, args);
}
}
application.yml
Eureka 是一个高可用的组件,它么有后端缓存,每一个实例注册之后需要向注册中心发送心跳(因此可以再内存中完成),在默认情况下 Erueka Server 也是一个 Eureka Client,必须要指定一个 Server。
spring:
application:
name: hello-spring-cloud-eurka
server:
port: 8761
eurka:
instance:
hostname: localhost
client:
# 表示是否将自己注册到 Eureka, 因为要构建集群环境,需要将自己注册到集群,所以应该开启
registerWithEurka: false
# 表示是否从 Eureka 获取注册信息,如果是单一节点,不需要同步其他 Eureka 节点,则可以设置为 false, 但此处为集群,应该设置为 true
fetchRegistry: false
serviceUrl:
defaultZone: http://${eurka.instance.hostname}:${server.port}/eurka/
通过 eureka.client.registerWithEureka:false
和 fetchRegistry:false
来表明自己是一个 Eureka Server。
操作界面
Eureka Server 是有界面得,启动工程,打开浏览器访问:
http://localhost:8761
还没有评论,来说两句吧...