【微服务之Eureka服务注册发现】

服务发现:云端负载均衡,一个基于 REST 的服务,用于定位服务,以实现云端的负载均衡和中间层服务器的故障转移。

一、代码如下

package com.didispace;

import org.springframework.boot.autoconfigure.SpringBootApplication;

import org.springframework.boot.builder.SpringApplicationBuilder;

import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;

@EnableEurekaServer

@SpringBootApplication

public class Application {

扫描二维码关注公众号,回复: 209287 查看本文章

public static void main(String[] args) {

new SpringApplicationBuilder(Application.class).web(true).run(args);

}

}

备注:

@EnableEurekaServer//开启Eureka Server

@SpringBootApplication//springBoot注解,spring在springBoot基础之上来构建项目



 

二、配置文件详解

server.port=1111

#eureka.instance.hostname=localhost

eureka.client.register-with-eureka=false

eureka.client.fetch-registry=false

eureka.client.serviceUrl.defaultZone=http://localhost:${server.port}/eureka/

这里解释一下:

server.port ---> 服务启动的端口

spring.application.name ---> 这是个服务名字,配置高可用以及其他服务访问该服务的时候,是通过这个属性找服务注册中心获取可用的访问ip的(当然你可以通过 ip 直接调用其他服务,那不如别用 sc 啦

eureka.client.serviceUrl.defaultZone ---> 这是服务注册的地址,后期说到高可用服务注册中心,你会看到这个属性多个地址是用英文逗号分割的

三、结果验证


 

猜你喜欢

转载自gaojingsong.iteye.com/blog/2411007