spring cloud(一) eureka

spring cloud 注册中心 eureka 搭建过程

1.搭建eureka-server 服务端

1.1. 新建boot工程 pom引入依赖

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

1.2.启动类添加注解@EnableEurekaServer

@SpringBootApplication
@EnableEurekaServer
public class EurekaApplication {

    public static void main(String[] args) {
        SpringApplication.run(EurekaApplication.class, args);
    }

}

1.3 application.properties添加配置

server.port=8761
spring.application.name=eureka-server
eureka.client.registerWithEureka=false
eureka.client.fetchRegistry=false
eureka.instance.prefer-ip-address=true

2.搭建eureka-client 客户端

2.1 新建boot工程 pom引入依赖

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

2.2.启动类添加注解@EnableDiscoveryClient

@SpringBootApplication
@EnableDiscoveryClient
public class ProductServiceApplication {

    public static void main(String[] args) {
        SpringApplication.run(ProductServiceApplication.class, args);
    }

}

2.3 application.properties添加配置

server.port=8082
spring.application.name=product-service
eureka.client.service-url.defaultZone=http://localhost:8761/eureka/
eureka.instance.hostname=localhost
eureka.instance.prefer-ip-address=true
eureka.instance.instance-id=${eureka.instance.hostname}:${server.port}

3.查看服务生效 

 

项目github 地址  https://github.com/yongxiangliu123/SpringCloud

posted @ 2019-06-25 10:52  农夫与蛇丶  阅读(178)  评论(0)    收藏  举报