简体   繁体   English

Spring Boot注册服务器(Eureka服务器)

[英]Spring Boot Registration Server(Eureka Server)

I am working on a Spring Boot Registration Server(Eureka Server). 我正在使用Spring Boot注册服务器(Eureka服务器)。 Currently it is working with below configuration. 目前,它正在使用以下配置。

Project Name: registration-service 项目名称:注册服务
Inside main method: System.setProperty("spring.config.name", "registration-service"); 内部主要方法: System.setProperty(“ spring.config.name”,“注册服务”);

"yml file": “ yml文件”:
file name: registration-service content: 文件名:注册服务内容:

     eureka:
      instance:
        hostname: eureka-server
      server:
        enableSelfPreservation: false
      client:
        register-with-eureka: false
        fetch-registry: false
        serviceUrl:
         defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/


    server:
      port: 2323   # HTTP (Tomcat) port




spring:
 application:
  name: eureka-server

With above configuration,application start running on 2323. But if i change spring.config.name ,it does not work,start giving connection refused exception. 通过上述配置,应用程序开始在2323上运行。但是,如果我更改spring.config.name ,则它不起作用,开始给出连接被拒绝的异常。

  1. why it is happening? 为什么会这样呢? even though this spring.config.name is no where used in yml file. 即使在yml文件中不使用spring.config.name,也是如此。 Should it be necessarily same as project name? 是否必须与项目名称相同? or it is specific to @EnableEurekaServer enabled spring boot application. 或特定于启用了@EnableEurekaServer的spring boot应用程序。

  2. And in yml we have to write 在yml中,我们必须编写

spring: application: name: eureka-server 春天:应用程序:名称:尤里卡服务器

though in other spring boot application we give name of current project(here it should be registration-service).why we have to write here eureka-server? 尽管在其他Spring Boot应用程序中,我们给出了当前项目的名称(此处应为registration-service)。为什么我们必须在此处编写eureka-server? I know,I am missing something(or a lot of things).please help me in understanding the missing part. 我知道,我缺少某些(或很多东西)。请帮助我理解缺失的部分。

Spring boot by default looks for file application.yml. 默认情况下,Spring Boot查找文件application.yml。 If u have different profiles in your application it can also look for application-{profilename}.yml. 如果您的应用程序中有不同的配置文件,它也可以查找application- {profilename} .yml。 This is the default convention followed. 这是遵循的默认约定。

spring.config.name property is used to override this default behaviour. spring.config.name属性用于覆盖此默认行为。 When u override this property with register-service then spring boot looks for a file register-service.yml and loads config from that. 当您使用register-service覆盖此属性时,spring boot会寻找一个文件register-service.yml并从中加载配置。

So your eureka server url which is given in the register-service.yml file may not be available in the default application.yml file. 因此,register-service.yml文件中提供的您的eureka服务器URL可能在默认的application.yml文件中不可用。 Hence when u change the value Spring boot may not be avle to find the Eureka server url. 因此,当您更改值时,Spring boot可能无法找到Eureka服务器URL。

Keep the names unchanged, as much as possible. 尽可能保持名称不变。 If u have config file as register-service.yml then keep the spring.config.name=register-service. 如果您有配置文件作为register-service.yml,则保留spring.config.name = register-service。 If you change this value then u need to create the new file with config.name value and then add eureka configuration to that again. 如果您更改此值,那么您需要使用config.name值创建新文件,然后再次向其中添加eureka配置。

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

相关问题 Spring 引导应用程序在 Eureka 服务器中显示为未知 - Spring Boot Application shown as UNKNOWN in Eureka server Spring Boot Eureka服务器仪表板错误 - Spring Boot Eureka server dashboard error 在 spring 引导中设置 eureka 服务器时出错 - Error setting up eureka server in spring boot 在Eureka服务器,Discovey和服务/应用程序的注册不是在Spring开发的 - In Eureka Server, Discovey and Registration of Services/Applications NOT developed in Spring Eureka 服务器在 spring 启动时出现错误 - Eureka Server while starting in spring boot getting the errors 在 Spring 引导应用程序中启动 Eureka 服务器时出错 - Error While Starting Eureka Server in Spring Boot Application 如何在不同主机上使用eureka-server注册eureka-clients。 春季启动 - How to register eureka-clients with eureka-server on different hosts. Spring-boot 带有配置服务器的 Spring Cloud Eureka - Spring Cloud Eureka with Config Server Spring 云Eureka服务器在启动eureka客户端服务后立即重启。 (升级JDK和Spring引导版本后。) - Spring Cloud Eureka server restarts as soon as eureka client service is started. (After upgrading JDK and Spring Boot version.) Spring启动,获取Docker暴露端口进行eureka注册 - Spring boot, get Docker exposed port for eureka registration
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM