spring cloud 服务提供者
1. pom 依赖:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.4.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</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Camden.SR7</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
</project>
2. 启动类:
@SpringBootApplication
@EnableEurekaClient
public class HelloApplication {
public static void main(String[] args) {
SpringApplication.run(HelloApplication.class, args);
}
}
3. 业务逻辑
@RestController
public class HelloController {
private static Logger LOG = LoggerFactory.getLogger(HelloController.class);
@Autowired
private DiscoveryClient client;
@RequestMapping("/hello")
public String hello() throws InterruptedException {
int time = new Random().nextInt(2000);
LOG.info("时长是:{}",time);
Thread.sleep(time);
ServiceInstance instance = client.getLocalServiceInstance();
String msg = "host:" + instance.getHost() + ",端口:" + instance.getPort() + ",serviceId:" + instance.getServiceId();
LOG.info(msg);
return msg;
}
}
4. 配置:
server:
port: 8086
spring:
application:
name: hello-service
eureka:
client:
serviceUrl:
defaultZone: http://admin:admin@ym-eureka-server1:8761/eureka/,http://admin:admin@ym-eureka-server2:8762/eureka/,http://admin:admin@ym-eureka-server3:8763/eureka/
instance:
preferIpAddress: true
spring cloud 服务提供者的更多相关文章
- Spring Cloud心跳监测
Spring Cloud实现心跳监测,在服务注册和停止时,注册中心能得到通知,并更新服务实例列表 Spring Cloud注册中心添加配置: eureka.server.enable-self-pre ...
- Spring Cloud第二篇 | 使用并认识Eureka注册中心
本文是Spring Cloud专栏的第二篇文章,了解前一篇文章内容有助于更好的理解本文: Spring Cloud第一篇 | Spring Cloud前言及其常用组件介绍概览 一.Sprin ...
- spring cloud (三、服务提供者demo_provider)
spring cloud (一.服务注册demo_eureka) spring cloud (二.服务注册安全demo_eureka) 创建一个服务提供者注册到服务注册中心,跟前一个案例一样创建一个s ...
- Spring Cloud(Dalston.SR5)--Eureka 服务提供者
要使微服务应用向注册中心发布自己,首先需要在 pom.xml 配置文件中增加对 spring-boot-starter-eureka 的依赖,然后在主类中增加 @EnableDiscoveryClie ...
- Spring Cloud入门程序——注册服务提供者
1.创建Spring Starter project 2.引入依赖 点击finish 3.创建启动类 package com.hello; import org.springframework.boo ...
- spring cloud 2.x版本 Eureka Client服务提供者教程
本文采用Spring cloud本文为2.1.8RELEASE,version=Greenwich.SR3 1 创建eureka client 1.1 新建Srping boot工程:eureka-c ...
- Spring cloud实战——服务提供者
目录讲解: 一.服务提供者与服务消费者的概念 二.编写一个服务提供者的测试类(code) 1.1. 使用微服务构建的是分布式系统,微服务之间通过网络进行通信.我们使用微服务提供者与服务消费者来描述微服 ...
- spring cloud:搭建基于consul的服务提供者集群(spring cloud hoxton sr8 / spring boot 2.3.4)
一,搭建基于consul的服务提供者集群 1,consul集群,共3个实例: 2, 服务提供者集群:共2个实例: 3,服务消费者:一个实例即可 4,consul集群的搭建,请参考: https://w ...
- Spring Cloud系列(二):服务提供者
上一篇介绍了注册中心,这一篇介绍如何把服务注册到注册中心. 一.创建服务提供者 我们依然使用上一篇的项目,在其中创建一个spring boot模块,填好必要的信息,依赖需要选择Spring Web和E ...
随机推荐
- JVM(下)
持久代:不会被 gc 给轻易回收的,创建后一直存在,持久代在堆内存里面,但是不归 java 程序使用.持久代是 动态 load 的那些 class,局部变量,去 gc 其实也 gc 不了啥 1.8 之 ...
- ORA-25205: the QUEUE SYS.KUPC$S_1_20180123193821 does not exist
[oracle@hbjfdba:/oratmp]#expdp \'XXX as sysdba\' DIRECTORY=TMP_DUMP_DIR DUMPFILE=NEW_LOCAL_HB_DMN_%U ...
- Linux & Oracle目录说明
/bin:存放着一百多个Linux下常用的命令.工具 /dev:存放着Linux下所有的设备文件! /home:用户主目录,每建一个用户,就会在这里新建一个与用户同名的目录,给该用户一个自己的空间 ...
- Anaconda 使用(解决python包管理与环境管理)
Anaconda完全入门指南(对python环境和原理,讲的比较透彻):https://www.jianshu.com/p/eaee1fadc1e9 用pip一个一个安装第三方库费时费力,还需要考虑兼 ...
- webpack 的插件 DllPlugin 和 DllReferencePlugin
在项目中,引入了比较多的第三方库,导致项目大,而每次修改,都不会去修改到这些库,构建却都要再打包这些库,浪费了不少时间.所以,把这些不常变动的第三方库都提取出来,下次 build 的时候不再构建这些库 ...
- bzoj 3611(洛谷 4103) [Heoi2014]大工程——虚树
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=3611 https://www.luogu.org/problemnew/show/P4103 ...
- Dynamics CRM 2011 报表无法显示的问题总结
一.一般打开报表会出现:该报表无法显示.(reProcessingAborted)和由于运行Microsoft SQL Server Reporting Services 的服务器上没有安装 Micr ...
- iis运行asp.net页面提示“服务器应用程序不可用”的解决办法_.NET.
原因:主要是iis安装在了net framwork之后 解决办法:需要在IIS中重新注册.net 也就是要用到系统盘: cd c:\windows\microsoft.net\framework\v2 ...
- Mysql 性能优化1 硬件设备的选择
--------------------------------------------目录------------------------------------------------- • 我们 ...
- wxWidgets:入门
0. 介绍 wxWidgets是一个开源的跨平台的C++构架库(framework),它可以提供GUI和其它工具.目前的3.0.0版本支持所有版本的Windows.带GTK+或Motif的Unix和M ...