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即可消费此服务。

  • 相关阅读:
    刷题86—动态规划(三)
    刷题85—动态规划(二)— 股票6道
    刷题84—动态规划(一)
    刷题83——硬币
    刷题82——二叉树的右视图
    刷题81——统计「优美子数组」
    android adb 流程原理代码分析(一)
    android默认开启adb调试方法分析
    recovery 下界面UI旋转90 180 270修改
    sublime使用Package Control不能正常使用的解决办法
  • 原文地址:https://www.cnblogs.com/geniushuangxiao/p/7219497.html
Copyright © 2011-2022 走看看