当前位置: 移动技术网 > IT编程>开发语言>Java > SpringCloud:1章 Eureka服务注册与发现

SpringCloud:1章 Eureka服务注册与发现

2020年07月27日  | 移动技术网IT编程  | 我要评论
  1. 新建Eureka模块
    在这里插入图片描述
  2. 配置yml文件
server:
  port: 2001
eureka:
  instance:
    hostname: localhost  #eurake实例名
  client:
    service-url:
      defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka
    register-with-eureka: false #表示不想注册中心注册自已
    fetch-registy: false #表示不需要检索服务

3.启动类加上@EnableEurekaServer注解

@EnableEurekaServer
@SpringBootApplication
public class DemoApplication {

    public static void main(String[] args) {
        SpringApplication.run(DemoApplication.class, args);
    }

}

4.访问http://www.lhsxpumps.com/_localhost:2001/ 出现如下画面则成功
在这里插入图片描述
5. 创建注册者模块
在这里插入图片描述
6. 配置yml文件

server:
  port: 2002

spring:
  application:
    name: clinet_1 #注册名字

eureka:
  client:
    service-url:
      defaultZone: http://localhost:2001/eureka

7.启动类加入注解@EnableEurekaClient

@EnableEurekaClient
@SpringBootApplication
public class DemoApplication {

    public static void main(String[] args) {
        SpringApplication.run(DemoApplication.class, args);
    }

}
  1. 检查依赖是否有这两个
<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-web</artifactId>
</dependency>
  1. 访问http://www.lhsxpumps.com/_localhost:2001 成功则出现
    在这里插入图片描述

本文地址:https://blog.csdn.net/weixin_42654295/article/details/107599449

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网