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

  • 相关阅读:
    50 个加速包都抢不到车票,还不如这个 Python 抢票神器!
    前后端开源的一款简单的微信个人博客小程序
    可以提升3倍开发效率的 Intellij IDEA快捷键大全汇总(2019)
    一张图搞定OAuth2.0
    nginx+vue实现项目动静分离
    「今日 GitHub 趋势」让全世界程序员体会中国的 12306 抢票狂潮
    C# 获取当前月第一天和最后一天
    connect to tomcat with JMX
    Java Debugging
    内存模型
  • 原文地址:https://www.cnblogs.com/geniushuangxiao/p/7219497.html
Copyright © 2011-2022 走看看