Невозможно запустить микросервис Spring с помощью Docker ComposeJAVA

Программисты JAVA общаются здесь
Anonymous
Невозможно запустить микросервис Spring с помощью Docker Compose

Сообщение Anonymous »

Создание микросервиса весенней загрузки с сервером конфигурации.
В настоящее время существует 3 службы:
  • сервер конфигурации.
  • почтовая служба
  • пользовательская служба
Проблема в том, Сервер конфигурации может запуститься правильно, а служба сообщений и пользователей — нет.
Ниже приведен файл docker-compose.yml:
version: '3.8'

services:
rabbit:
image: rabbitmq:3.12-management
hostname: rabbitmq
ports:
- "5672:5672"
- "15672:15672"
healthcheck:
test: rabbitmq-diagnostics check_port_connectivity
interval: 10s
timeout: 5s
retries: 10
start_period: 5s
networks:
- app-network

postgres:
image: postgres:latest
container_name: postgres
ports:
- "5431:5432"
environment:
POSTGRES_DB: blog
POSTGRES_USER: postgresuser
POSTGRES_PASSWORD: postgrespassword
deploy:
resources:
limits:
memory: 512m
volumes:
- ~/volume/userservice-postgres/data:/var/lib/postgresql/data
- ./init.sql:/docker-entrypoint-initdb.d/init.sql
networks:
- app-network

configserver:
image: example/configserver
container_name: configserver
ports:
- "8071:8071"
deploy:
resources:
limits:
memory: 700m
depends_on:
rabbit:
condition: service_healthy
healthcheck:
test: "curl --fail --silent http://localhost:8071/actuator/health/readiness | grep UP || exit 1"
interval: 10s
timeout: 5s
retries: 10
start_period: 20s
networks:
- app-network

userservice:
image: example/userservice
container_name: userservice
ports:
- "8081:8081"
environment:
SPRING_APPLICATION_NAME: userservice
SPRING_DATASOURCE_URL: jdbc:postgresql://postgres:5431/userservice
SPRING_DATASOURCE_USERNAME: postgresuser
SPRING_DATASOURCE_PASSWORD: postgrespassword
CONFIG_SERVER: http://configserver:8071
SPRING_PROFILES_ACTIVE: prod
deploy:
resources:
limits:
memory: 700m
depends_on:
configserver:
condition: service_healthy
rabbit:
condition: service_healthy
postgres:
condition: service_started
networks:
- app-network

postservice:
image: example/postservice
container_name: postservice
ports:
- 8082:8082
environment:
SPRING_APPLICATION_NAME: postservice
SPRING_DATASOURCE_URL: jdbc:postgresql://postgres:5431/postservice
SPRING_DATASOURCE_USERNAME: postgresuser
SPRING_DATASOURCE_PASSWORD: postgrespassword
CONFIG_SERVER: http://configserver:8071
SPRING_PROFILES_ACTIVE: prod
deploy:
resources:
limits:
memory: 700m
depends_on:
configserver:
condition: service_healthy
rabbit:
condition: service_healthy
postgres:
condition: service_started
networks:
- app-network

networks:
app-network:
driver: bridge

Это трассировка стека:
serservice |
userservice | 2024-08-05T07:32:22.288Z INFO 1 --- [userservice] [ restartedMain] o.s.c.c.c.ConfigServerConfigDataLoader : Fetching config from server at : http://localhost:8071/
userservice | 2024-08-05T07:32:22.289Z INFO 1 --- [userservice] [ restartedMain] o.s.c.c.c.ConfigServerConfigDataLoader : Exception on Url - http://localhost:8071/:org.springframew ... sException: I/O error on GET request for "http://localhost:8071/userservice/default": Connection refused. Will be trying the next url if available
userservice | 2024-08-05T07:32:22.290Z INFO 1 --- [userservice] [ restartedMain] o.s.c.c.c.ConfigServerConfigDataLoader : Fetching config from server at : http://localhost:8071/
userservice | 2024-08-05T07:32:22.290Z INFO 1 --- [userservice] [ restartedMain] o.s.c.c.c.ConfigServerConfigDataLoader : Exception on Url - http://localhost:8071/:org.springframew ... sException: I/O error on GET request for "http://localhost:8071/userservice/prod": Connection refused. Will be trying the next url if available
userservice | 2024-08-05T07:32:22.393Z ERROR 1 --- [userservice] [ restartedMain] o.s.boot.SpringApplication : Application run failed
userservice |
userservice | org.springframework.cloud.config.client.ConfigClientFailFastException: Could not locate PropertySource and the resource is not optional, failing
userservice | at org.springframework.cloud.config.client.ConfigServerConfigDataLoader.doLoad(ConfigServerConfigDataLoader.java:210) ~[spring-cloud-config-client-4.1.3.jar:4.1.3]
userservice | at org.springframework.cloud.config.client.ConfigClientRetryBootstrapper.lambda$initialize$1(ConfigClientRetryBootstrapper.java:54) ~[spring-cloud-config-client-4.1.3.jar:4.1.3]
userservice | at org.springframework.cloud.config.client.ConfigServerConfigDataLoader.load(ConfigServerConfigDataLoader.java:95) ~[spring-cloud-config-client-4.1.3.jar:4.1.3]
userservice | at

application.yml выглядит следующим образом:
spring:
application:
name: userservice
config:
import: "configserver:${CONFIG_SERVER:http://localhost:8071/}"



Подробнее здесь: https://stackoverflow.com/questions/788 ... er-compose

Вернуться в «JAVA»