3 Star 1 Fork 0

huayousoft / spring-cloud-demo

Create your Gitee Account
Explore and code with more than 6 million developers,Free private repositories !:)
Sign up
Clone or download
Cancel
Notice: Creating folder will generate an empty file .keep, because not support in Git
Loading...
README.md

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 相互注册即可

Comments ( 0 )

Sign in for post a comment

About

No description spread retract
Java
Apache-2.0
Cancel

Releases

No release

Contributors

All

Activities

load more
can not load any more
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

Search