我正试着把我的弹簧启动微型服务转移到码头工人身上。当在本地系统上实现STS时,我的微服务运行得非常好。但是,当我对它们进行修改时,我会得到一个连接超时错误。
我在下面分享我的代码片段:
Docker-compose:
version: '3.6'
services:
db:
image: 'mysql:8.0.18'
container_name: mysqldb
ports:
- '3300:3300'
environment:
- MYSQL_ROOT_PASSWORD=root
- MYSQL_USER=root
networks:
- truyum-nw
- movie-cruiser-nw
volumes:
- './mysqldb:/var/lib/mysql'
- './dbscripts:/docker-entrypoint-initdb.d'
config-server:
image: spring-cloud-config-server
build: ./spring-cloud-config-server
container_name: spring-cloud-config-server
ports:
- '8888:8888'
networks:
- truyum-nw
- movie-cruiser-nw
eureka:
image: eureka-discovery-service
build: ./eureka-discovery-service
container_name: eureka-discovery
ports:
- '8761:8761'
depends_on:
- config-server
- db
networks:
- truyum-nw
- movie-cruiser-nw
zuul:
image: zuul-service
build: ./zuul-gateway
container_name: zuul-bridge
ports:
- '8762:8762'
depends_on:
- eureka
- config-server
networks:
- truyum-nw
- movie-cruiser-nw
auth-service:
image: auth-service
build: ./Authentication-service
container_name: auth-service
ports:
- '9100:9100'
depends_on:
- eureka
- config-server
networks:
- truyum-nw
- movie-cruiser-nw
menu-item-service:
image: menu-item-service
build: ./menuitem-service
container_name: menu-item-service
ports:
- '34000:34000'
depends_on:
- eureka
- config-server
- zuul
- db
- auth-service
networks:
- truyum-nw
cart-service:
image: cart-service
build: ./cart-service
container_name: cart-service
ports:
- '34001:34001'
depends_on:
- eureka
- config-server
- zuul
- db
- menu-item-service
- auth-service
networks:
- truyum-nw
movie-service:
image: movie-service
build: ./movie-service
container_name: movie-service
ports:
- '35000:35000'
depends_on:
- eureka
- config-server
- db
- zuul
- auth-service
networks:
- movie-cruiser-nw
favourite-service:
image: favourite-service
build: ./favorite-service
container_name: favourite-service
ports:
- '35001:35001'
depends_on:
- eureka
- config-server
- db
- zuul
- auth-service
- movie-service
networks:
- movie-cruiser-nw
networks:
truyum-nw:
name: truyum-nw
driver: bridge
movie-cruiser-nw:
name: movie-cruiser-nw
driver: bridgeapplication.properties of spring-cloud-config-server
spring.cloud.config.server.git.uri = https://github.com/satyamthedeveloper/Stage4_Week2_841418_SatyamKumar
server.port=8888application.properties of Eureka-Discovery-Server
spring.application.name=discoveryservice
spring.cloud.config.uri = http://spring-cloud-config-server:8888当我执行docker-compose up并检查http://localhost:8888/discoveryservice/default时,我得到的结果如下
{
"name": "discoveryservice",
"profiles": [
"default"
],
"label": null,
"version": "8450532e432fb103ef30d0002fa254b23d2158d6",
"state": null,
"propertySources": [
{
"name": "https://github.com/satyamthedeveloper/Stage4_Week2_841418_SatyamKumar/discoveryservice.properties",
"source": {
"server.port": "8761",
"eureka.client.register-with-eureka": "false",
"eureka.client.fetch-registry": "false",
"info.app.name": "Spring Eureka Server Application"
}
},
{
"name": "https://github.com/satyamthedeveloper/Stage4_Week2_841418_SatyamKumar/application.yml",
"source": {
"eureka.client.service-url.defaultZone": "http://eureka-discovery:8761/eureka",
"logging.level.org.springframework.web": "DEBUG",
"management.endpoints.web.exposure.include": "*"
}
}
]
}但是,我的Eureka discovery service从8080开始,因为我还没有公开它,这是无法访问的。我尝试过这些步骤中的几个,但没有帮助。
我不知道为什么我的服务不能获取链接,我可以很容易地使用URL获取链接。

发布于 2020-07-08 21:32:29
在配置服务器的eureka配置中必须引用的名称仅为config-server,因为这是撰写yaml中的服务名称。
发布于 2020-07-10 02:09:20
花了两天的时间,我要这样解决这个问题:
我将在application.properties中定义的属性转换为bootstrap.yml。这些变化如下。
spring-cloud-config-server的bootstrap.yml
spring:
application:
name: config-server
cloud:
config:
server:
git:
uri: https://github.com/satyamthedeveloper/Stage4_Week2_841418_SatyamKumar
clone-on-start: trueEureka-Discovery-Server的bootstrap.yml
spring:
application:
name: discoveryservice
cloud:
config:
fail-fast: true
retry:
maxAttempts: 200
maxInterval: 10000
uri: http://spring-cloud-config-server:8888在了解了bootstrap.yml和application.properties之间的区别之后,我们了解了这种错误背后的原因。
使用application.properties是
我们使用application.yml或application.properties来配置应用程序上下文。 当Spring应用程序启动时,它会创建一个不需要显式配置的应用程序上下文--它已经自动配置了。然而,Spring提供了不同的方法来覆盖这些属性。
和bootstrap.yml的使用是
我们使用bootstrap.yml或bootstrap.properties来配置引导上下文。这样,我们就可以很好地分离引导和主上下文的外部配置。 引导上下文负责从外部源加载配置属性并解密本地外部配置文件中的属性。 当Spring应用程序启动时,它会创建一个引导上下文。首先要记住的是,引导上下文是主应用程序的父上下文。 要记住的另一个要点是,这两个上下文共享环境,它是任何Spring应用程序的外部属性的来源。与应用程序上下文不同,引导上下文使用不同的约定来定位外部配置。
您可以参考以下博客获得更详细的信息:Application.properties与Bootstrap.yml的区别及实例
发布于 2021-10-15 06:25:01
实际上,在运行docker-come.yml时,有一个映像(针对ex :8761)不知道localhost:8888(您的配置服务器)。
属性/ yml文件正在返回localhost:端口到eureka映像,它需要连接到其他图像/实例,但是有一个映像需要其他图像uri (即名称:港口 ),因此需要将它作为环境变量传递出去。
在eureka映像下添加环境变量配置服务器uri,即在docker-compose.yml:中添加
eureka:
image: eureka-discovery-service
build: ./eureka-discovery-service
container_name: eureka-discovery
ports:
- '8761:8761'
depends_on:
- config-server
environment:
# Important for clients to register with config server
- spring.config.import=optional:configserver:http://config-server:8888
- db
networks:
- truyum-nw
- movie-cruiser-nw此外,如果您需要在任何eureka客户端中传递eureka,则需要在eureka客户端映像下将其作为环境变量传递。
environment:
# Important for clients to register with eureka
eureka.client.serviceUrl.defaultZone=http://discovery-service:8761/eureka/在上面的代码中,8761 service是eureka服务器的服务名称(在端口8761中)。
https://stackoverflow.com/questions/62800536
复制相似问题