第三章 SpringCloud之Eureka-Client服务提供者
1、Eureka-Client简介
#################接下来开始程序啦##########################
1、pom.xml
<?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>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.3.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.test</groupId>
<artifactId>eureka-client</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>eureka-client</name>
<description>Demo project for Spring Boot</description> <properties>
<java.version>1.8</java.version>
<spring-cloud.version>Greenwich.SR1</spring-cloud.version>
</properties> <dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency> <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies> <dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement> <build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build> </project>
从pom.xml中可以看出,pom.xml的配置是在springboot的基础上添加了一个依赖,即
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
2、在application.yml添加配置文件
server:
port: 8662 #服务端口
spring:
application:
name: eureka-client #虚拟主机名
eureka:
client:
serviceUrl:
defaultZone: http://${eureka.instance.hostname}:8761/eureka/ #将这个服务注册到eurekaserver上
instance:
hostname: localhost
prefer-ip-address: true
instance-id: ${spring.application.name}:${spring.application.instance_id:${server.port}} #修改注册到eureka的名字
3、在启动类添加注解(@EnableEurekaClient)
package com.test.eurekaclient; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient; @SpringBootApplication
@EnableEurekaClient
public class EurekaClientApplication {
public static void main(String[] args) {
SpringApplication.run(EurekaClientApplication.class, args);
} }
4、访问URL
http://localhost:8661/
可以看到如下的服务

第三章 SpringCloud之Eureka-Client服务提供者的更多相关文章
- spring cloud 2.x版本 Eureka Client服务提供者教程
本文采用Spring cloud本文为2.1.8RELEASE,version=Greenwich.SR3 1 创建eureka client 1.1 新建Srping boot工程:eureka-c ...
- SpringCloud学习笔记(三、SpringCloud Netflix Eureka)
目录: 服务发现简介 SpringCloud Netflix Eureka应用 Eureka高可用 Eureka源码分析 >>> Eureka Client初始化(客户端定时获取服务 ...
- Spring Cloud03: Eureka Client 服务提供者
一.创建一个子工程并引入配置如下: <dependency> <groupId>org.springframework.cloud</groupId> <ar ...
- SpringCloud创建Eureka Client服务注册
1.说明 本文详细介绍微服务注册到Eureka的方法, 即Eureka Client注册到Eureka Server, 这里用任意一个Spring Cloud服务为例, 比如下面已经创建好的Confi ...
- SpringCloud学习第三章-springcloud 父项目创建
父项目 pom.xml <?xml version="1.0" encoding="UTF-8"?> <project xmlns=" ...
- SpringCloud2.0 Eureka Client 服务注册 基础教程(三)
1.创建[服务提供者],即 Eureka Client 1.1.新建 Spring Boot 工程,工程名称:springcloud-eureka-client 1.2.工程 pom.xml 文件添加 ...
- SpringCloud创建Config Client通过Eureka访问Config
1.说明 本文详细介绍配置中心客户端使用方法, 即Config Client到Config Server读取配置. 读取配置的方式有两种, 第一种是直接配置Configer Server的URL, 第 ...
- SpringCloud搭建Eureka集群
第一部分:搭建Eureka Server集群 Step1:新建工程,引入依赖 依赖文件pom.xml如下 <?xml version="1.0" encoding=" ...
- springcloud(二) eureka的使用
上一节讲到order微服务是通过rest调用user微服务的地址.但是,user微服务的地址是写死的, 如果user微服务集群的话,那么order微服务该如何调用呢?这个时候注册中心该上场了 演示eu ...
随机推荐
- deep_learning_Function_numpy_argmax()函数
numpy里面的argmax函数 函数原型:def argmax(a, axis=None, out=None)a----输入arrayaxis----为0代表列方向,为1代表行方向out----结果 ...
- 可靠的TCP连接为何是三次握手和四次挥手
首先,咱们先来熟悉下经典的tcp/ip模型. tcp/ip 模型为了方便使用,将osi七层模型划分成了四层,分别为网络接口层,网络层,传输层,应用层. 他们作用分别为: 1)网络接口层:主要作用是将i ...
- SpringMVC获取HttpClient 请求的数据
package com.nnk.upstream.controller;import org.springframework.util.StreamUtils;import javax.servlet ...
- oracle修改某个表的字段顺序
有时候会发现某个表的列顺序不理想,想修改 -1查询表, select * from AIRWAY_TYPE t --2 查询用户和表名,找到obj#,select object_id from all ...
- session共享原理以及PHP 实现多网站共享用户SESSION 数据解决方案
参考自: http://www.cnblogs.com/qulinke/articles/6003049.html https://segmentfault.com/q/101000000578847 ...
- Redis和Memcache对比及选择(转载)
原文地址:http://blog.csdn.net/sunmenggmail/article/details/36176029 没有必要过多的关注性能.由于Redis只使用单核,而Memcached可 ...
- 最近老是有兄弟问我,Vue双向绑定的原理,以及简单的原生js写出来实现,我就来一个最简单的双向绑定,原生十行代码让你看懂原理
废话不多说直接看效果图 代码很好理解,但是在看代码之前需要知道Vue双向绑定的原理其实就是基于Object.defineProperty 实现的双向绑定 官方传送门 这里我们用官方的话来说Object ...
- 2017 去哪儿网 研发4.18(offer)
去哪儿网一面(30分钟) 上来小哥哥先让自我介绍,然后开始问基础,说你计算机专业的,数据结构应该比较扎实吧,先写个快排.然后在我写的时候,小哥哥mac上敲敲打打,应该在看git,我简历上有留git的地 ...
- 【leetcode】1187. Make Array Strictly Increasing
题目如下: Given two integer arrays arr1 and arr2, return the minimum number of operations (possibly zero ...
- javascript中创建对象的方式及优缺点(二)
一.工厂模式 流程: 定义一个函数,函数返回对象. 适用场景: 需要创建多个对象,都是Object类型. 优点:完成了返回一个对象的要求. 缺点: 对象没有一个具体的类型,无法通过constructo ...