# spring-cloud-demo
**Repository Path**: huayousoft/spring-cloud-demo
## Basic Information
- **Project Name**: spring-cloud-demo
- **Description**: No description available
- **Primary Language**: Java
- **License**: Apache-2.0
- **Default Branch**: master
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 1
- **Forks**: 0
- **Created**: 2020-11-19
- **Last Updated**: 2020-12-19
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
# spring-cloud-demo
#### 介绍
spring-cloud-demo用于学习springcloud框架演示应用。
#### Eureka教程
1. 搭建eureka-server步骤
1.1 引入依赖
```xml
org.springframework.cloud
spring-cloud-starter-netflix-eureka-server
```
1.2 配置yml文件
```yaml
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 配置启动类
```java
@SpringBootApplication
@EnableEurekaServer
public class EurekaApplication {
public static void main(String[] args) {
SpringApplication.run(EurekaApplication.class,args);
}
}
```
2. 搭建Eureka-Client 步骤
2.1 引入依赖
```xml
org.springframework.cloud
spring-cloud-starter-netflix-eureka-client
```
2.2 配置yml文件
```yaml
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 配置启动类
```java
/**
*
* @author ZhangHua
*
* * @EnableDiscoveryClient == @EnableEurekaClient 注解作用一样,可以不用写
*/
//@EnableEurekaClient
//@EnableDiscoveryClient
@SpringBootApplication
public class GoodsApplication {
public static void main(String[] args) {
SpringApplication.run(GoodsApplication.class, args);
}
}
```
3. Eureka高可用集群
Eureka 相互注册即可