zoukankan      html  css  js  c++  java
  • 002服务提供者Eureka

    1、POM配置

      和普通Spring Boot工程相比,仅仅添加了Eureka、Spring Boot Starter Actuator依赖和Spring Cloud依赖管理

    <dependencies>
      <!--添加Eureka Server依赖-->
      <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-eureka</artifactId>
      </dependency>
      <!--服务健康检测,务必添加,不然负载均衡消费此服务时,断路器会打开-->
      <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-actuator</artifactId>
      </dependency>
    </dependencies>
    <dependencyManagement>
      <dependencies>
        <!--Spring Cloud依赖版本管理-->
        <dependency>
          <groupId>org.springframework.cloud</groupId>
          <artifactId>spring-cloud-dependencies</artifactId>
          <version>Dalston.SR1</version>
          <type>pom</type>
          <scope>import</scope>
        </dependency>
      </dependencies>
    </dependencyManagement>

    02、使能Eureka Client

    @SpringBootApplication
    @EnableEurekaClient//使能Eureka Server服务
    public class Application {
        public static void main(String[] args) {
            SpringApplication.run(Application.class, args);
        }
    }

    03、src/main/resources工程配置文件application.yml

    server:
      port: 2001  #默认启动端口
    spring:
      application:
        name: hello-service-provider #应用名

    eureka:   instance:     hostname: hello-service-provider  #主机名
      client:
        serviceUrl:
          defaultZone: http://localhost:1000/eureka/ #服务注册中心地址。若部署在其它IP主机,请将localhost改为主机IP

    04、提供服务

    @RestController
    public class HelloController {
        @GetMapping("/hello")
        public String hello() {
            System.out.println("Time" + System.currentTimeMillis());
            return "Hello Spring Cloud";
        }
    }

      服务消费者通过http://hello-service-provider/hello即可消费此服务。

  • 相关阅读:
    游戏开发制作流程详细介绍
    成为群体领袖
    别人的,值得借鉴的经验
    linux下iptabes配置详解
    Oracle tnsnames.ora
    同时展多个物料BOM List
    Oracle判断是否为数字或数字型字符串
    linux上的vnc配置
    Oracle 中的正则函数
    如何将 backordered 的SO# 重新发运?
  • 原文地址:https://www.cnblogs.com/geniushuangxiao/p/7219497.html
Copyright © 2011-2022 走看看