首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >云配置获得请求执行错误。来自尤里卡服务器的http://localhost:8761/}{serviceUrl=‘endpoint=DefaultEndpoint

云配置获得请求执行错误。来自尤里卡服务器的http://localhost:8761/}{serviceUrl=‘endpoint=DefaultEndpoint
EN

Stack Overflow用户
提问于 2019-03-25 11:15:18
回答 3查看 24.3K关注 0票数 5

我正在尝试为我的4项微服务实现方式。首先是从git获取配置的配置服务器,其次是Eureka服务器。当我运行docker时,我的配置服务器无法向eureka注册。我有:

请求执行错误。endpoint=DefaultEndpoint{ serviceUrl='http://localhost:8761/}连接被拒绝

我的配置服务器

代码语言:javascript
复制
 @EnableConfigServer
    @EnableEurekaClient
    @SpringBootApplication
    public class ConfigServerApplication {
        public static void main(String[] args) {
            SpringApplication.run(ConfigServerApplication.class, args);
        }

application.yml

代码语言:javascript
复制
   server:
  port: 8888
spring:
  cloud:
    config:
      server:
        encrypt.enabled: false
        git:
          uri: https://github.com/Artuwok/artbook-config-repo/
          searchPaths: userservice
          username: Artuwok
          password: Civilization1986
          timeout: 10
          force-pull: true

bootstrap.yml

代码语言:javascript
复制
spring:
  application:
    name: configserver
  cloud:
    config:
      fail-fast: true
      discovery.enabled: true

eureka:
  client:
    registerWithEureka: true
    fetchRegistry: true
    serviceUrl.defaultZone: http://localhost:8761/eureka/

Eureca类

代码语言:javascript
复制
@SpringBootApplication
@EnableEurekaServer
public class EurekaServerApplication {

    public static void main(String[] args) {
        SpringApplication.run(EurekaServerApplication.class, args);
    }

尤里卡bootstrap.yml

代码语言:javascript
复制
server:
  port: 8761
eureka:
  client:
    registerWithEureka: false
    fetchRegistry: false

docker-compose.yml与完整配置

代码语言:javascript
复制
version: '3'

services:

  configserver:
    image: configserver:1.0
    ports:
      - "8888:8888"
    depends_on:
      - eurekaserver
    restart: on-failure

  eurekaserver:
    image: eurekasvr:1.0
    ports:
      - "8761:8761"


  users_db:
    image: mysql:5.7
    container_name: users_db
    restart: always
    environment:
      - MYSQL_DATABASE=artbook
      - MYSQL_ROOT_PASSWORD=password
      - MYSQL_USER=user
      - MYSQL_PASSWORD=password
    volumes:
      - users_db:/var/lib/mysql
    ports:
      - "3306:3306"
    depends_on:
      - eurekaserver

  user-service:
    image: userservice:1.0
    ports:
      - "8080:8080"
    depends_on:
      - eurekaserver
      - configserver
    restart: on-failure
volumes:
  users_db:

所以最终我得以启动这些服务。请注意您正在发现服务的URL。如果您正在使用映像,则必须使用服务名称,而不是uri和uri中的本地主机.我的工作配置

代码语言:javascript
复制
spring:
  application:
    name: configserver
  cloud:
    config:
      fail-fast: false
      discovery.enabled: false
      uri: http://configserver:8888

eureka:
  client:
    registerWithEureka: true
    fetchRegistry: true
    serviceUrl.defaultZone: http://eurekaserver:8761/eureka
EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2019-03-25 12:03:17

配置服务器和Eureka服务器都在Docker中运行。这样他们就可以在Docker而不是localhost上使用自己的名字相互联系。

所以尤里卡服务网址应该是:http://eurekaserver:8761/

您应该将下面的代码添加到configserver配置中的docker-compose.yml中。

代码语言:javascript
复制
links:
    - eurekaserver
票数 6
EN

Stack Overflow用户

发布于 2021-05-07 21:37:00

在应用程序中添加以下属性文件:

注册-与-eureka=false eureka.client.FETCH-注册表=false

这使得您的eureka服务器在默认端口8080上运行,这些属性还帮助您不将eurekaServer注册到自己。

(EurekaServer本身也是一个客户。)

如果要在端口8761上运行此服务器,请在application.properties文件中添加以下内容:

server.port=8761

PS-当你不使用码头时,它会有所帮助。

票数 3
EN

Stack Overflow用户

发布于 2022-10-09 07:57:34

我没有使用docker,但是我也收到了同样的错误,我在网上搜索了很多,但是没有发现任何东西。

然后,我只需停止服务器,只更新一次maven依赖项,然后尝试启动它的服务发现。成功了!!

我希望这能帮到一个人,他没有使用和停靠,得到了同样的。

也要确保在application.propertiesapplication.yml中有这些配置

代码语言:javascript
复制
server.port=8761
spring.application.name=eureka-discovery
eureka.instance.hostname=localhost
eureka.client.register-with-eureka=false 
eureka.client.fetch-registry=false
eureka.client.service-url.defaultZone: http://localhost:8761/eureka
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55336558

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档