我有以下问题。我有两个spring boot微服务(1.5.8 ver),一个配置服务和一个发现服务。 当我在本地运行它们时,服务正在启动并成功通信。
现在,当我使用docker compose文件启动这两项服务时,我收到以下错误:
Request execution failed with message: java.net.ConnectException: Connection refused (Connection refused)
discovery-svc | WARN 24 --- [nfoReplicator-0] com.netflix.discovery.DiscoveryClient : DiscoveryClient_DISCOVERY/6c4a9f118423:discovery - registration failed Cannot execute request on any known server
discovery-svc |
discovery-svc | com.netflix.discovery.shared.transport.TransportException: Cannot execute request on any known server
discovery-svc | at com.netflix.discovery.shared.transport.decorator.RetryableEurekaHttpClient.execute(RetryableEurekaHttpClient.java:111) ~[eureka-client-1.7.0.jar!/:1.7.0]
discovery-svc | at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator.register(EurekaHttpClientDecorator.java:56) ~[eureka-client-1.7.0.jar!/:1.7.0]
discovery-svc | at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator$1.execute(EurekaHttpClientDecorator.java:59) ~[eureka-client-1.7.0.jar!/:1.7.0]
discovery-svc | at com.netflix.discovery.shared.transport.decorator.SessionedEurekaHttpClient.execute(SessionedEurekaHttpClient.java:77) ~[eureka-client-1.7.0.jar!/:1.7.0]
discovery-svc | at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator.register(EurekaHttpClientDecorator.java:56) ~[eureka-client-1.7.0.jar!/:1.7.0]
discovery-svc | at com.netflix.discovery.DiscoveryClient.register(DiscoveryClient.java:807) ~[eureka-client-1.7.0.jar!/:1.7.0]
discovery-svc | at com.netflix.discovery.InstanceInfoReplicator.run(InstanceInfoReplicator.java:104) [eureka-client-1.7.0.jar!/:1.7.0]
discovery-svc | at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [na:1.8.0_151]
discovery-svc | at java.util.concurrent.FutureTask.run(FutureTask.java:266) [na:1.8.0_151]
discovery-svc | at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180) [na:1.8.0_151]
discovery-svc | at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293) [na:1.8.0_151]
discovery-svc | at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [na:1.8.0_151]
discovery-svc | at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [na:1.8.0_151]
discovery-svc | at java.lang.Thread.run(Thread.java:748) [na:1.8.0_151]
discovery-svc |
discovery-svc | 2017-12-20 15:19:00.314 WARN 24 --- [nfoReplicator-0] c.n.discovery.InstanceInfoReplicator : There was a problem with the instance info replicator
discovery-svc |
discovery-svc | com.netflix.discovery.shared.transport.TransportException: Cannot execute request on any known server
discovery-svc | at com.netflix.discovery.shared.transport.decorator.RetryableEurekaHttpClient.execute(RetryableEurekaHttpClient.java:111) ~[eureka-client-1.7.0.jar!/:1.7.0]
discovery-svc | at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator.register(EurekaHttpClientDecorator.java:56) ~[eureka-client-1.7.0.jar!/:1.7.0]
discovery-svc | at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator$1.execute(EurekaHttpClientDecorator.java:59) ~[eureka-client-1.7.0.jar!/:1.7.0]
discovery-svc | at com.netflix.discovery.shared.transport.decorator.SessionedEurekaHttpClient.execute(SessionedEurekaHttpClient.java:77) ~[eureka-client-1.7.0.jar!/:1.7.0]
discovery-svc | at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator.register(EurekaHttpClientDecorator.java:56) ~[eureka-client-1.7.0.jar!/:1.7.0]
discovery-svc | at com.netflix.discovery.DiscoveryClient.register(DiscoveryClient.java:807) ~[eureka-client-1.7.0.jar!/:1.7.0]
discovery-svc | at com.netflix.discovery.InstanceInfoReplicator.run(InstanceInfoReplicator.java:104) ~[eureka-client-1.7.0.jar!/:1.7.0]
discovery-svc | at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [na:1.8.0_151]
discovery-svc | at java.util.concurrent.FutureTask.run(FutureTask.java:266) [na:1.8.0_151]
discovery-svc | at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180) [na:1.8.0_151]
discovery-svc | at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293) [na:1.8.0_151]
discovery-svc | at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [na:1.8.0_151]
discovery-svc | at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [na:1.8.0_151]
discovery-svc | at java.lang.Thread.run(Thread.java:748) [na:1.8.0_151]
我有以下文件: 搬运工-compose.yml
version: '3.4'
services:
config-svc:
image: "config-img"
container_name: config-svc
build:
context: ../config
dockerfile: docker/config.dockerfile
expose:
- "8888"
discovery-svc:
image: "discovery-img"
container_name: discovery-svc
build:
context: ../discovery
dockerfile: docker/discovery.dockerfile
depends_on:
- config-svc
links:
- config-svc:config-svc
entrypoint: sh -c '/tmp/wait-for config-svc:8888 && java -jar discovery.jar'
expose:
- "8761"
发现服务:bootstrap.yml
spring:
application:
name: discovery
cloud:
config:
uri: http://config-svc:8888
profiles:
active: docker
management:
security:
enabled: false
配置服务:bootstrap.yml
server:
port: 8888
spring:
application:
name: config
cloud:
config:
server:
native:
search-locations: ${user.dir}/src/main/resources/configs
profiles:
active:
- native
security:
basic:
enabled: false
management:
security:
enabled: false
discovery.docker.properties
server.port=8761
eureka.client.register-with-eureka=false
eureka.client.fetch-registry=false
eureka.client.serviceUrl.defaultZone=http://discovery-svc:8761/eureka/
eureka.instance.hostname=discovery-svc
eureka.instance.preferIpAddress=false
logging.level.com.netflix.eureka=OFF
logging.level.com.netflix.discovery=OFF
我尝试过很多东西,但没有运气。 任何人都可以提出任何建议吗?
提前致谢
答案 0 :(得分:0)
config-svc
和服务discovery-svc
通信。尝试将驱动程序设置为bridge
,如下所示
version: '3.4'
services:
config-svc:
image: "config-img"
container_name: config-svc
build:
context: ../config
dockerfile: docker/config.dockerfile
expose:
- "8888"
networks:
- app-network
discovery-svc:
image: "discovery-img"
container_name: discovery-svc
build:
context: ../discovery
dockerfile: docker/discovery.dockerfile
depends_on:
- config-svc
links:
- config-svc:config-svc
entrypoint: sh -c '/tmp/wait-for config-svc:8888 && java -jar discovery.jar'
expose:
- "8761"
networks:
- app-network
networks:
app-network:
driver: brige
答案 1 :(得分:0)
好的,我找到了。问题出在bootstrap.yml文件的配置服务中,spring.cloud.config.server.native.search-locations的属性值必须固定为classpath:configs。现在它工作正常。
感谢您的回复