3 Star 1 Fork 0

huayousoft / spring-cloud-demo

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
README.md 1.92 KB
一键复制 编辑 原始数据 按行查看 历史
zhanghua4j 提交于 2020-11-25 18:45 . readme

spring-cloud-demo

介绍

spring-cloud-demo用于学习springcloud框架演示应用。

Eureka教程

  1. 搭建eureka-server步骤

1.1 引入依赖

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

1.2 配置yml文件

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

1.3 配置启动类

@SpringBootApplication
@EnableEurekaServer
public class EurekaApplication {
    public static void main(String[] args) {
        SpringApplication.run(EurekaApplication.class,args);
    }
}
  1. 搭建Eureka-Client 步骤

2.1 引入依赖

<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>

2.2 配置yml文件

eureka:
  client:
    service-url:
      defaultZone: http://localhost:8761/eureka
  instance:
    prefer-ip-address: true
    instance-id: ${spring.cloud.client.ip-address}:${server.port}
    lease-renewal-interval-in-seconds: 5 #向注册中心注册服务的心跳间隔时间
    lease-expiration-duration-in-seconds: 10 #续约到期时间

2.3 配置启动类

/**
 *
 * @author ZhangHua
 *
 * * @EnableDiscoveryClient == @EnableEurekaClient 注解作用一样,可以不用写
 */
//@EnableEurekaClient
//@EnableDiscoveryClient
@SpringBootApplication
public class GoodsApplication {
    public static void main(String[] args) {
        SpringApplication.run(GoodsApplication.class, args);
    }
}
  1. Eureka高可用集群 Eureka 相互注册即可
Java
1
https://gitee.com/huayousoft/spring-cloud-demo.git
git@gitee.com:huayousoft/spring-cloud-demo.git
huayousoft
spring-cloud-demo
spring-cloud-demo
master

搜索帮助