栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 前沿技术 > 大数据 > 大数据系统

SpringCloud Eureka服务注册发现中心

SpringCloud Eureka服务注册发现中心

1.什么是Eureka

Eureka是Netflix公司开源的一个服务注册与发现的组件。和Consul、Zookeeper类似。

2.项目结构


父工程pom



    4.0.0

    com.porridge.www
    springcloud-eureka
    pom
    1.0-SNAPSHOT

    
        eureka-server
        eureka-client
    

    
        org.springframework.boot
        spring-boot-starter-parent
        2.0.3.RELEASE
        
    

    
        UTF-8
        UTF-8
        1.8
        Finchley.RELEASE
    

    
        
            
                org.springframework.cloud
                spring-cloud-dependencies
                ${spring-cloud.version}
                pom
                import
            
        
    

3.创建子工程(服务注册发现中心) eureka-server

pom文件



    
        springcloud-eureka
        com.porridge.www
        1.0-SNAPSHOT
    
    4.0.0

    eureka-server

    
        
            org.springframework.cloud
            spring-cloud-starter-netflix-eureka-server
        
    
    

application.yml文件

server:
  port: 8761

eureka:
  instance:
    hostname: localhost
  client:
    registerWithEureka: false
    fetchRegistry: false
    serviceUrl:
      defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/

spring:
  application:
    name: eurka-server

EurekaServerApplication

@SpringBootApplication
//开启eureka注册发现
@EnableEurekaServer
public class EurekaServerApplication {
    public static void main(String[] args) {
        SpringApplication.run(EurekaServerApplication.class,args);
    }
}

访问localhost:8761

3.创建子工程(服务) eureka-client

pom文件



    
        springcloud-eureka
        com.porridge.www
        1.0-SNAPSHOT
    
    4.0.0

    eureka-client
    
        
            org.springframework.cloud
            spring-cloud-starter-netflix-eureka-client

        
        
            org.springframework.boot
            spring-boot-starter-web

        
    

application.yml

server:
  port: 8762

eureka:
  instance:
    hostname: localhost
  client:
    serviceUrl:
      defaultZone: http://localhost:8761/eureka/

spring:
  application:
    name: eurka-client

EurekaClientApplication

@SpringBootApplication
//开启向eureka注册功能
@EnableEurekaClient
public class EurekaClientApplication {
    public static void main(String[] args) {
        SpringApplication.run(EurekaClientApplication.class,args);
    }
}

IndexController控制层

@RestController
public class IndexController {
    @RequestMapping("/")
    public String indexService(){
        return "this is indexService";
    }

}

再次访问localhost:8761

访问localhost:8762

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/784955.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号