简体   繁体   English

如何向Eureka客户端注册Spring 5应用程序

[英]How to register spring 5 application to eureka client

Thank you for your reply. 谢谢您的回复。 i don't know what registers spring(5) application as eureka client. 我不知道什么将spring(5)应用程序注册为eureka客户端。 my application is just read data. 我的应用程序只是读取数据。 i found that example code before, but i can't apply some code. 我之前找到了示例代码,但是我无法应用某些代码。 and i didn't know what how to execute eureka client code when start my application. 而且我不知道在启动我的应用程序时如何执行eureka客户端代码。

found code 找到的代码

DiscoveryManager.getInstance().initComponent(new MyDataCenterInstanceConfig(), new DefaultEurekaClientConfig());

  String vipAddress = "MY-SERVICE";

    InstanceInfo nextServerInfo = null;
    try {
        nextServerInfo = DiscoveryManager.getInstance()
                .getEurekaClient()
                .getNextServerFromEureka(vipAddress, false);
    } catch (Exception e) {
        System.err.println("Cannot get an instance of example service to talk to from eureka");
        System.exit(-1);
    }

    System.out.println("Found an instance of example service to talk to from eureka: "
            + nextServerInfo.getVIPAddress() + ":" + nextServerInfo.getPort());

    System.out.println("healthCheckUrl: " + nextServerInfo.getHealthCheckUrl());
    System.out.println("override: " + nextServerInfo.getOverriddenStatus());

    System.out.println("Server Host Name "+ nextServerInfo.getHostName() + " at port " + nextServerInfo.getPort() );

i thought my application executes url "/" in MainController when start. 我以为我的应用程序在启动时会在MainController中执行网址“ /”。 so, i just that code writes in "/" GetMapping method of MainController. 所以,我只是代码写在MainController的“ /” GetMapping方法中。 but i got a error this. 但是我有一个错误。 cannot access javax.inject.Provider class file for javax.inject.Provider not found. 无法访问javax.inject.Provider的javax.inject.Provider类文件。

how to make code for registers as eureka client and how to use that code... please help junior! 如何注册为尤里卡客户的注册代码以及如何使用该代码...请大三帮助! thanks! 谢谢!

Why don't you try use configuration files? 为什么不尝试使用配置文件? example: application.properties or yml? 例如:application.properties或yml?

Eureka Server: 尤里卡服务器:

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

Microservices Client: 微服务客户端:

eureka:
  instance:
    hostname: localhost
    port: 9091
  client:
    registerWithEureka: true
    fetchRegistry: false
    serviceUrl:
      defaultZone: http://${eureka.instance.hostname}:${eureka.instance.port}/eureka/
  server:
    wait-time-in-ms-when-sync-empty: 3000

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM