# springcloud **Repository Path**: igzhang/springcloud ## Basic Information - **Project Name**: springcloud - **Description**: springcloud - **Primary Language**: Java - **License**: GPL-3.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2022-10-07 - **Last Updated**: 2022-10-07 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # springcloud #### 介绍 springcloud微服务项目搭建 消费者模块:springcloud-consumer-dept-80 生产者模块:springcloud-provider-dept-8001 注册中心:springcloud-eureka-7001、springcloud-eureka-7002、springcloud-eureka-7003 引入springcloud依赖 ```xml org.springframework.cloud spring-cloud-dependencies 2021.0.4 pom import org.springframework.boot spring-boot-dependencies 2.7.2 pom import ``` #### 使用 eureka 服务注册中心 引入依赖 ```xml org.springframework.cloud spring-cloud-starter-netflix-eureka-server 2.1.3.RELEASE org.springframework.cloud spring-cloud-starter-netflix-eureka-client 2.1.3.RELEASE ``` ```yaml #Eureka 注册中心配置 eureka: instance: hostname: eureka7001 #Eureka 服务的实例名称 client: register-with-eureka: false #表示是否向Erueka注册中心注册自己,该项目本身是服务,不用注册 fetch-registry: false #表示自己就是注册中心 service-url: #监控页面 #单机 #defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka #集群 defaultZone: http://eureka7002:7002/eureka/,http://eureka7003:7003/eureka/ ``` ```yaml #Eureka客户端配置 eureka: client: service-url: #集群配置方式 defaultZone: http://eureka7001:7001/eureka/,http://eureka7002:7002/eureka/,http://eureka7003:7003/eureka/ instance: instance-id: springcloud-provider-dept-8001 #修改eureka上的默认描述信息 ``` ```java @SpringBootApplication @EnableEurekaServer //开启Eureka服务端 public class EurekaServer_7001 { public static void main(String[] args) { SpringApplication.run(EurekaServer_7001.class,args); } } ``` ```java @SpringBootApplication @EnableEurekaClient //在服务启动后自动注册到Eureka注册中心 public class DeptProvider_8001 { public static void main(String[] args) { SpringApplication.run(DeptProvider_8001.class,args); } } ```