SpringCloud学习笔记(1):Eureka注册中心

简介
Eureka是Netflix开源的基于rest的服务治理方案,分为Server端和Client端,Server端为注册中心,其他微服务通过Client端连接Server端进行服务的注册和发现。
项目介绍
  • sc-parent,父模块
  • sc-provider,提供者模块
  • sc-eureka,注册中心
  • sc-consumer-discovery,消费者模块
搭建父模块
创建父模块sc-parent,pom.xml:
<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>  <groupId> com.cf</groupId>  <artifactId>sc-parent</artifactId>  <version>0.0.1-SNAPSHOT</version>  <packaging>pom</packaging>      <!-- 继承Spring Boot的默认值 -->   <parent>       <groupId>org.springframework.boot</groupId>       <artifactId>spring-boot-starter-parent</artifactId>       <version>2.1.6.RELEASE</version>       <relativePath /> <!-- lookup parent from repository -->   </parent>      <properties>    <!-- 降低maven-jar-plugin插件版本,防止版本不匹配导致的pom.xml第一行报错 -->    <maven-jar-plugin.version>3.1.1</maven-jar-plugin.version>   </properties>      <dependencies>        <!-- 添加web应用依赖 -->        <dependency>            <groupId>org.springframework.boot</groupId>            <artifactId>spring-boot-starter-web</artifactId>        </dependency>   </dependencies>      <dependencyManagement>        <dependencies>            <!-- SpringCloud依赖 -->            <dependency>                <groupId>org.springframework.cloud</groupId>                <artifactId>spring-cloud-dependencies</artifactId>                <version>Greenwich.SR2</version>                <type>pom</type>                <scope>import</scope>            </dependency>        </dependencies>   </dependencyManagement>      <build>        <plugins>               &l
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
将Spring Cloud Config Server注册到Eureka注册中心的步骤如下: 1. 首先需要在pom.xml文件中添加Eureka Client的依赖,如下所示: ```xml <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId> <version>2.2.1.RELEASE</version> </dependency> ``` 2. 在应用程序的配置文件中添加以下配置: ```yaml eureka: client: serviceUrl: defaultZone: http://localhost:8761/eureka/ ``` 其中,`defaultZone`指定了Eureka Server的地址。 3. 在Spring Boot应用程序类上添加@EnableEurekaClient注解,以将Config Server注册到Eureka Server上: ```java @EnableConfigServer @EnableDiscoveryClient @SpringBootApplication public class ConfigServerApplication { public static void main(String[] args) { SpringApplication.run(ConfigServerApplication.class, args); } } ``` 4. 运行Config Server应用程序,查看Eureka Server的管理页面(http://localhost:8761)上是否已经注册成功。 5. 客户端应用程序可以通过以下方式从Config Server获取配置: ```yaml spring: application: name: client-service cloud: config: uri: http://localhost:8888 fail-fast: true retry: maxAttempts: 20 multiplier: 1.5 maxInterval: 5000 label: master ``` 其中,`cloud.config.uri`指定了Config Server的地址,`spring.application.name`指定了客户端应用程序的名称,`label`指定了Git仓库的分支名称。 6. 运行客户端应用程序,即可从Config Server获取配置。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值