Spring cloud Eureka 服务治理(注册服务提供者)
搭建完成服务注册中心,下一步可以创建服务提供者并向注册中心注册服务。
接下来我们创建Spring Boot 应用将其加入Eureka服务治理体系中去。
直接使用签名章节创建hello服务项目改造:
1. 添加Eureka服务治理依赖配置
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka-server</artifactId>
</dependency>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Brixton.SR5</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
2. 改造RestController服务接口的/hello服务
/**
* Created by Administrator on 2017/5/9.
*/ @RestController
public class HelloController { private final Logger log = Logger.getLogger(getClass()); @Autowired
private DiscoveryClient client; @RequestMapping(value = "/hello", method = RequestMethod.GET)
public String index(){ ServiceInstance instance = client.getLocalServiceInstance(); log.info("/hello, host:" + instance.getHost() + ", service_id:" + instance.getServiceId()); return "Hello World !";
} }
3. 激活Eureka 的DiscoveryClient实现,添加 @EnableDiscoveryClient 注解
@EnableDiscoveryClient
@SpringBootApplication
@ComponentScan("com.net263")
public class HelloworldApplication { public static void main(String[] args) {
SpringApplication.run(HelloworldApplication.class, args);
}
}
4. 配置application.properties 关键参数
# 指定应用名称
spring.application.name= hello-service # 构建服务中心的地址
eureka.client.serviceUrl.defaultZone= http://localhost:1111/eureka/
改造完毕,下面我们分别启动注册中心服务和提供服务者程序。启动成功后会打印如下日志信息说明注册服务成功。

也可以去服务注册中心信息面板去查看。

通过访问:http://wmlocal.263.net:8888/hello 向服务发起请求,在控制台中可以看到如下输出

Spring cloud Eureka 服务治理(注册服务提供者)的更多相关文章
- Spring cloud Eureka 服务治理(搭建服务注册中心)
服务之类是微服务架构中最为核心的基础模块,它主要用来实现各个微服务实例的自动化注册和发现. 1. 服务注册 在服务治理框架中,通常会构建一个注册中心,每个服务单元向注册中心登记自己提供的服务,将主机. ...
- 1 Spring Cloud Eureka服务治理
注:此随笔为读书笔记.<Spring Cloud微服务实战> 什么是微服务? 微服务是将一个原本独立的系统拆分成若干个小型服务(一般按照功能模块拆分),这些小型服务都在各自独立的进程中运行 ...
- 笔记:Spring Cloud Eureka 服务治理
Spring Cloud Eureka 是 Spring Cloud Netflix 微服务套件的一部分,基于 Netflix Eureka 做了二次封装,主要负责完成微服务架构中的服务治理功能,服务 ...
- Spring Cloud Eureka 服务治理
Spring Cloud Eureka 是 Spring Cloud Netflix 微服务套件的一部分,基于 Netflix Eureka 做了二次封装,主要负责完成微服务架构中的服务治理功能,服务 ...
- 1 Spring Cloud Eureka服务治理(上)
注:此随笔为读书笔记.<Spring Cloud微服务实战>,想学习Spring Cloud的同伴们可以去看看此书,里面对源码有详细的解读. 什么是微服务? 微服务是将一个原本独立的系统拆 ...
- 1 Spring Cloud Eureka服务治理(下)
注:此随笔为读书笔记.<Spring Cloud微服务实战> 上篇主要介绍了什么是微服务以及微服务治理的简单实现,如微服务注册中心的实现.微服务注册的实现.微服务的发现和消费的实现.微服务 ...
- Spring Cloud Eureka 服务治理机制
服务提供者 服务提供者在启动的时候会通过发送REST请求的方式将自己注册到Eureka Server上,同时带上了自身服务的一些元数据信息.Eureka Server 接收到这个RE ...
- Spring cloud Eureka 服务治理(高可用服务中心)
在微服务的架构中,我们考虑发生故障的情况,所以在生产环境中我们需要对服务中各个组件进行高可用部署. Eureka Server 的高可用实际上就是将自己作为服务想其它服务注册中心注册自己,这样就形成了 ...
- Spring Cloud (1) 服务的注册与发现(Eureka)
Spring Cloud简介 Spring Cloud是一个基于Spring Boot实现的云应用开发工具,它为基于JVM的云应用开发中涉及的配置管理.服务发现.断路器.智能路由.微代理.控制总线.全 ...
随机推荐
- 差一点搞混了Transactional注解
今天给我的Srping业务层加如下Service和Transactional注解: @Service @Scope(BeanDefinition.SCOPE_SINGLETON) @Transacti ...
- 【256】◀▶IEW-答案
附答案 Unit I Fast food Model Answers: Model 1 The pie chart shows the fast foods that teenagers prefer ...
- HTTP ERROR
HTTP 400 – 请求无效HTTP 401.1 – 未授权:登录失败HTTP 401.2 – 未授权:服务器配置问题导致登录失败HTTP 401.3 – ACL 禁止访问资源HTTP 401.4 ...
- SPOJ - REPEATS Repeats (后缀数组+RMQ)
题意:求一个串中出现重复子串次数最多的数目. 析:枚举每个长度的子串,至少要重复两次,必然会经过s[l*i]中相邻的两个,然后再分别向前和向后匹配即可. 代码如下: #pragma comment(l ...
- idea中,使用Gradle创建的项目,如何变为web项目
当idea开发项目时,使用gradle构建项目,包引用完后,发现idea并没有正确识别项目为web项目. 主要有两点表现: 1. src/main/resources的resources目录没有或有但 ...
- vs2013使用git报错
之前使用的是个人git账号,先转换为公司git账号,在同步时报Response status code does not indicate success: 403 (Forbidden) 上述问题是 ...
- Protocol Buffers官方文档(开发指南)
本文是对官方文档的翻译,然后截取了一篇非常优秀的文章片段来帮助理解,本人英文水平有限,基本都是直译,如果有不理解的地方请参考英文官方文档,参考的文章链接在文章末尾 protocol buffers简介 ...
- 2018杭电多校第二场1003(DFS,欧拉回路)
#include<bits/stdc++.h>using namespace std;int n,m;int x,y;int num,cnt;int degree[100007],vis[ ...
- AOP常用注解
1.@Aspect 配置切面Bean,和<bean.../>元素进行配置无区别,一样支持依赖注入来配置属性值: 如果启动了Spring的"零配置"特性,一样可以让Spr ...
- mybatis笔记 - 初始配置及dao的封装
1.用户实体类 package com.javasm.entity; /** * *TODO 用户表实体类 * @author CaoLei 2018年6月26日上午10:50:12 * Manage ...