SpringCloud 入门搭建服务注册与发现

1、创建一个maven项目,添加依赖包:

<!-- eureka 注册中心服务端 -->
<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency>
<!-- web -->
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
</dependency>

2、修改或添加application.yml(或者bootstrap.yml)文件:

server:
  port: 8800

spring:
  application:
    name: moli-register

eureka:
  server:
    enable-self-preservation: false
    eviction-interval-timer-in-ms: 6000
  instance:
    prefer-ip-address: true
    ip-address: 127.0.0.1
    instance-id: ${spring.application.name}:${spring.cloud.client.ip-address}:${spring.application.instance_id:${server.port}}
  client:
    registerWithEureka: false
    fetchRegistry: false
    serviceUrl:
      defaultZone: http://${eureka.instance.ip-address}:${server.port}/eureka/

3、编写服务注册与发现启动类:

package com.molicloud.moli.register;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;

/**
 * 注册中心
 * @author feitao <yyimba@qq.com> 2019/6/18 17:34
 */
@SpringBootApplication
@EnableEurekaServer
public class MoliRegisterApplication {

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

项目工程截图(请忽略我的config目录):

茉莉服务注册与发现-模块截图

未经允许不得转载:小茉莉 » SpringCloud 入门搭建服务注册与发现

赞 (1) 打赏

评论 1

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
  1. 冬天的秘密老哥测试一下回复

觉得文章有用就打赏一下小茉莉

支付宝扫一扫打赏

微信扫一扫打赏