Docker - SpringConfig - 拒绝连接到 ConfigServer [英] Docker - SpringConfig - Connection refused to ConfigServer

查看:37
本文介绍了Docker - SpringConfig - 拒绝连接到 ConfigServer的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 DockerCompose 部署具有远程存储库的 ConfigServrService 和客户端.

I'm trying to deploy a ConfigServrService and a Client with a remote repository using DockerCompose.

docker-compose.yml 是这样的:

The docker-compose.yml is like:

version: '2'

services:

  rabbitmq:
    image: rabbitmq
    ports:
      - "5672:5672"

  config-server:
    image: config-server
    environment:
      - "SPRING_PROFILES_ACTIVE=desa"
    ports:
      - "8888:8888"
    links:
      - rabbitmq
    depends_on:
      - rabbitmq

  user-service-config:
    image: user-service-config
    environment:
      - "SPRING_PROFILES_ACTIVE=desa"
    ports:
      - "8090:8090"
    links:
      - config-server
      - rabbitmq
    depends_on:
      - rabbitmq
      - config-server

在部署时,客户端控制台显示:

At the moment that they are deploying, the client console shows:

c.c.c.ConfigServicePropertySourceLocator:从服务器获取配置在:http://localhost:8888

c.c.c.ConfigServicePropertySourceLocator : Fetching config from server at: http://localhost:8888

(而不是 http://config-server:8888)

之后,控制台显示:

无法定位 PropertySource:在 GET 请求中出现 I/O 错误"http://localhost:8888/user-server-config/desa":拒绝连接;嵌套异常是 java.net.ConnectException:连接被拒绝

Could not locate PropertySource: I/O error on GET request for "http://localhost:8888/user-server-config/desa": Connection refused; nested exception is java.net.ConnectException: Connection refused

该服务正在尝试连接到 http://localhost:8888/user-server-config/desa 而不是 http://config-server:8888.

The service is trying to connet to http://localhost:8888/user-server-config/desa instead of http://config-server:8888.

客户端的application.yml文件为:

The application.yml file of the client is:

server:
  port: 8090
spring:
  rabbitmq:
    host: 172.17.0.1
    port: 5672
    username: guest
    password: guest

  application:
    name: user-server-config
  cloud:
    enabled: true
    config:
      uri: http://config-server:8888
      failFast: true
      retry:
        maxAttempts: 20

management:
  security:
    enabled: false

我不知道为什么 uri 包含 http://localhost:8888/user-server-config/desa 最后.而不是应用程序中指示的 http://server-config:8888.yml

I do not know why the uri contains http://localhost:8888 with /user-server-config/desa at the end. Instead of http://server-config:8888 as is indicated in the application.yml

推荐答案

spencergibb 所建议的 这里,以及官方文档 建议,创建一个 bootstrap.yml 文件:

As suggested by spencergibb here, and as the official documentation suggests, create a bootstrap.yml file:

spring:
  cloud:
    enabled: true
    config:
      uri: http://config-server:8888
      failFast: true
      retry:
        maxAttempts: 20

并从 application.yml 中删除上述包含的属性.

and remove the above included properties from application.yml.

这篇关于Docker - SpringConfig - 拒绝连接到 ConfigServer的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆