Eureka(1)入门配置

一、eureka 服务端程序配置

 

1、引入依赖        pom.xml

        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
            <version>3.1.4</version>
        </dependency>

2、设置启动类        

//启动类添加注解:@EnableEurekaServer
@EnableEurekaServer
@SpringBootApplication
public class ServerApplication {
    public static void main(String[] args) {
        SpringApplication.run(EurekaApplication.class,args);
    }
}

3、配置eureka属性        application.yml

spring:
  application:
    name: eurekaserver
server:
  port: 10086
eureka:
  instance:
    hostname: localhost
  client:
    fetch-registry: false
    service-url:
      defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/

4、进入eureka服务页面

#        成功注册服务端--注册自己本身        eureka-server

​​​​​​​


二、eureka 客户端程序配置

1、引入依赖        pom.xml

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
            <version>3.1.4</version>
        </dependency>
    </dependencies>

2、设置启动类    

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

@EnableEurekaClient
@SpringBootApplication
public class ClientApplication {
    public static void main(String[] args) {
        SpringApplication.run(ClientApplication.class, args);
    }
}

3、配置eureka属性        application.yml 

spring:
  application:
    name: eureka-client
server:
  port: 10010
eureka:
  instance:
    hostname: localhost
  client:
    #    注册到指定的服务器地址中
    service-url:
      defaultZone: http://127.0.0.1:10086/eureka/

4、进入eureka服务页面

#        成功注册客户端      eureka-client

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值