0

I'm trying to make an example of Spring Cloud. I have problem on Docker side. when I run docker-compose,

  1. Keycloak,rabbitmq,mysql and config server are running.

  2. Here is my error in Eureka Server

    Connect Timeout Exception

Request execution error. endpoint=DefaultEndpoint{ serviceUrl='http://eurekaserver:8761
/eureka/}, exception=I/O error on GET request for "http://eurekaserver:8761/eureka/apps/": Connect to eurekaserver:8761 [eurekaserver/172.22.0.6] failed: Connection refused (Connection
 refused); nested exception is org.apache.http.conn.HttpHostConnectException: Connect to eurekaserver:8761 [eurekaserver/172.22.0.6] failed: Connection refused (Connection refused) sta
cktrace=org.springframework.web.client.ResourceAccessException: I/O error on GET request for "http://eurekaserver:8761/eureka/apps/": Connect to eurekaserver:8761 [eurekaserver/172.22.
0.6] failed: Connection refused (Connection refused); nested exception is org.apache.http.conn.HttpHostConnectException: Connect to eurekaserver:8761 [eurekaserver/172.22.0.6] failed:
Connection refused (Connection refused)

3 ) Here is my error in API Gateway

    DiscoveryClient_API-GATEWAY/5b93576f14b7:api-gateway:8600: registering service...
2022-08-18 21:15:16.082  INFO 1 --- [nfoReplicator-0] c.n.d.s.t.d.RedirectingEurekaHttpClient  : Request execution error. endpoint=DefaultEndpoint{ serviceUrl='http://localhost:8761/eu
reka/}, exception=I/O error on POST request for "http://localhost:8761/eureka/apps/API-GATEWAY": Connect to localhost:8761 [localhost/127.0.0.1] failed: Connection refused (Connection
refused); nested exception is org.apache.http.conn.HttpHostConnectException: Connect to localhost:8761 [localhost/127.0.0.1] failed: Connection refused (Connection refused) stacktrace=
org.springframework.web.client.ResourceAccessException: I/O error on POST request for "http://localhost:8761/eureka/apps/API-GATEWAY": Connect to localhost:8761 [localhost/127.0.0.1] f
ailed: Connection refused (Connection refused); nested exception is org.apache.http.conn.HttpHostConnectException: Connect to localhost:8761 [localhost/127.0.0.1] failed: Connection re
fused (Connection refused)

4 ) Here is my error in Management Service

    Request execution error. endpoint=DefaultEndpoint{ serviceUrl='http://eurekaserver:8761
/eureka/}, exception=I/O error on POST request for "http://eurekaserver:8761/eureka/apps/MANAGEMENT-SERVICE": Connect to eurekaserver:8761 [eurekaserver/172.22.0.6] failed: Connection
refused (Connection refused); nested exception is org.apache.http.conn.HttpHostConnectException: Connect to eurekaserver:8761 [eurekaserver/172.22.0.6] failed: Connection refused (Conn
ection refused) stacktrace=org.springframework.web.client.ResourceAccessException: I/O error on POST request for "http://eurekaserver:8761/eureka/apps/MANAGEMENT-SERVICE": Connect to e
urekaserver:8761 [eurekaserver/172.22.0.6] failed: Connection refused (Connection refused); nested exception is org.apache.http.conn.HttpHostConnectException: Connect to eurekaserver:8
761 [eurekaserver/172.22.0.6] failed: Connection refused (Connection refused)
  1. Here is my errors in User Service, Advertisement Service and Report Service
    DiscoveryClient_USER-SERVICE/468d01e02e11:user-service:9000: registering service...
2022-08-18 21:10:59.300  INFO 1 --- [nfoReplicator-0] c.n.d.s.t.d.RedirectingEurekaHttpClient  : Request execution error. endpoint=DefaultEndpoint{ serviceUrl='http://eurekaserver:8761
/eureka/}, exception=I/O error on POST request for "http://eurekaserver:8761/eureka/apps/USER-SERVICE": Connect to eurekaserver:8761 [eurekaserver/172.22.0.6] failed: Connection refuse
d (Connection refused); nested exception is org.apache.http.conn.HttpHostConnectException: Connect to eurekaserver:8761 [eurekaserver/172.22.0.6] failed: Connection refused (Connection
 refused) stacktrace=org.springframework.web.client.ResourceAccessException: I/O error on POST request for "http://eurekaserver:8761/eureka/apps/USER-SERVICE": Connect to eurekaserver:
8761 [eurekaserver/172.22.0.6] failed: Connection refused (Connection refused); nested exception is org.apache.http.conn.HttpHostConnectException: Connect to eurekaserver:8761 [eurekas
erver/172.22.0.6] failed: Connection refused (Connection refused)

Here is my docker compose file.

services:

  database:
    container_name: mysql-database
    image: 'mysql:latest'
    ports:
      - "3366:3306"
    restart: always
    environment:
      #MYSQL_DATABASE: "springbootuser"
      MYSQL_USER: "springmicroserviceuser"
      MYSQL_PASSWORD: "111111"
      MYSQL_ROOT_PASSWORD: "111111"
    volumes:
      - db-data:/var/lib/mysql
    networks:
      - backend
    healthcheck:
      test: ["CMD", "mysqladmin" ,"ping", "-h", "localhost"]
      timeout: 20s
      retries: 10

  keycloak:
    image: quay.io/keycloak/keycloak:18.0.2
    environment:
      - KEYCLOAK_ADMIN=admin
      - KEYCLOAK_ADMIN_PASSWORD=admin
    ports:
      - "8181:8080"
    networks:
      - backend
    command:
      - start-dev

  rabbitmq:
    image: "rabbitmq:3-management"
    container_name: "rmq3"
    environment:
      RABBITMQ_DEFAULT_USER: "rabbitmq"
      RABBITMQ_DEFAULT_PASS: "123456"
    ports:
      - "5672:5672"
      - "15672:15672"
    networks:
      - backend

  configserver:
    image: configserver
    container_name: configServer
    build:
      context: ./configserver
      dockerfile: Dockerfile
    #environment:
      #CONFIGSERVER_URI: "http://configserver:9191"
      #CONFIGSERVER_PORT: "9191"
    ports:
      - "9191:9191"
    networks:
      - backend

  eurekaserver:
    image: eurekaserver
    ports:
      - "8761:8761"
    build:
      context: ./discoveryserver
      dockerfile: Dockerfile
    environment:
      #CONFIGSERVER_URI: "http://configserver:9191"
      #CONFIGSERVER_PORT: "9191"
      SPRING_CLOUD_CONFIG_URI: "http://configserver:9191"
      EUREKA_CLIENT_SERVICEURL_DEFAULTZONE: "http://eurekaserver:8761/eureka/"
      #EUREKASERVER_PORT: "8761"
      WAIT_HOSTS: configserver:9191
    depends_on:
      configserver:
        condition: service_started
    networks:
      - backend


  gatewayserver:
    image: gatewayserver
    ports:
      - "8600:8600"
    build:
      context: ./api-gateway
      dockerfile: Dockerfile
    environment:
      PROFILE: "default"
      SERVER_PORT: "8600"
      #CONFIGSERVER_URI: "http://configserver:9191"
      SPRING_CLOUD_CONFIG_URI: "http://configserver:9191"
      EUREKA_CLIENT_SERVICEURL_DEFAULTZONE: "http://eurekaserver:8761/eureka/"
      #EUREKASERVER_PORT: "8761"
      #CONFIGSERVER_PORT: "9191"
      WAIT_HOSTS: configserver:9191
    depends_on:
      configserver:
        condition: service_started
      eurekaserver:
        condition: service_started
      userservice:
        condition: service_started
      managementservice:
        condition: service_started
      advertisementservice:
        condition: service_started
      reportservice:
        condition: service_started
    networks:
      - backend

  userservice:
    image: user-service
    build:
      context: ./user-service
      dockerfile: Dockerfile
    environment:
      SERVER_PORT: "9000"
      #CONFIGSERVER_URI: "http://configserver:9191"
      #CONFIGSERVER_PORT: "9191"
      SPRING_CLOUD_CONFIG_URI: "http://configserver:9191"
      EUREKA_CLIENT_SERVICEURL_DEFAULTZONE: "http://eurekaserver:8761/eureka/"
      #EUREKASERVER_PORT: "8761"
      WAIT_HOSTS: configserver:9191
      DATABASE_HOST: database
      DATABASE_USER: springmicroserviceuser
      DATABASE_PASSWORD: 111111
      DATABASE_NAME: springbootuser
      DATABASE_PORT: 3306
      SPRING_APPLICATION_JSON: '{
              "spring.jpa.hibernate.ddl-auto" : "update"
      }'
    depends_on:
      database:
        condition: service_healthy
      configserver:
        condition: service_started
      eurekaserver:
        condition: service_started
      keycloak:
        condition: service_started
    ports:
      - "9000:9000"
    networks:
      - backend

  managementservice:
    image: management-service
    build:
      context: ./management-service
      dockerfile: Dockerfile
    environment:
      SERVER_PORT: "9002"
      #CONFIGSERVER_URI: "http://configserver:9191"
      #CONFIGSERVER_PORT: "9191"
      SPRING_CLOUD_CONFIG_URI: "http://configserver:9191"
      EUREKA_CLIENT_SERVICEURL_DEFAULTZONE: "http://eurekaserver:8761/eureka/"
      #EUREKASERVER_PORT: "8761"
      WAIT_HOSTS: configserver:9191
    depends_on:
      configserver:
        condition: service_started
      eurekaserver:
        condition: service_started
    ports:
      - "9002:9002"
    networks:
      - backend

  advertisementservice:
    image: advertisement-service
    build:
      context: ./advertisement-service
      dockerfile: Dockerfile
    environment:
      SERVER_PORT: "9001"
      CONFIGSERVER_URI: "http://configserver:9191"
      CONFIGSERVER_PORT: "9191"
      EUREKA_CLIENT_SERVICEURL_DEFAULTZONE: "http://eurekaserver:8761/eureka/"
      EUREKASERVER_PORT: "8761"
      WAIT_HOSTS: configserver:9191
      DATABASE_HOST: database
      DATABASE_USER: springmicroserviceuser
      DATABASE_PASSWORD: 111111
      DATABASE_NAME: springbootadvertisement
      DATABASE_PORT: 3306
      SPRING_APPLICATION_JSON: '{
                  "spring.jpa.hibernate.ddl-auto" : "update"
      }'
    depends_on:
      database:
        condition: service_healthy
      configserver:
        condition: service_started
      eurekaserver:
        condition: service_started
      rabbitmq:
        condition: service_started
    ports:
      - "9001:9001"
    networks:
      - backend


  reportservice:
    image: report-service
    build:
      context: ./report-service
      dockerfile: Dockerfile
    environment:
      SERVER_PORT: "9003"
      CONFIGSERVER_URI: "http://configserver:9191"
      CONFIGSERVER_PORT: "9191"
      EUREKA_CLIENT_SERVICEURL_DEFAULTZONE: "http://eurekaserver:8761/eureka/"
      EUREKASERVER_PORT: "8761"
      WAIT_HOSTS: configserver:9191
      DATABASE_HOST: database
      DATABASE_USER: springmicroserviceuser
      DATABASE_PASSWORD: 111111
      DATABASE_NAME: springbootreport
      DATABASE_PORT: 3306
      SPRING_APPLICATION_JSON: '{
                      "spring.jpa.hibernate.ddl-auto" : "update"
      }'
    depends_on:
      database:
        condition: service_healthy
      configserver:
        condition: service_started
      eurekaserver:
        condition: service_started
      rabbitmq:
        condition: service_started
    ports:
      - "9003:9003"
    networks:
      - backend

networks:
  backend:
    driver: bridge


volumes:
  db-data:

Here is the project link : Link

Here are some screenshots for my issues : Link

1st Edited : I defined them for user, report and advertisement service.

SPRING_DATASOURCE_DRIVER_CLASS_NAME: java.sql.Driver
SPRING_DATASOURCE_DIALECT: org.hibernate.dialect.MySQL8Dialect

I got errors shown below.

Caused by: java.lang.RuntimeException: Failed to instantiate class java.sql.Driver
java.lang.NoSuchMethodException: java.sql.Driver.<init>()

2nd Editted : Here is the logs of eureka server : Link

3rd Editted : Updated docker-compose.yml

4th Editted : Here is the logs of eureka server : Link

5th Editted : Here is the new logs of each services : Link

2
  • I could see GET request for "http://configserver:9191/discovery-server/default" got a Connection Refused exception. I searched for this API in your github. Couldn't find. Is it really exists? @qwercan Commented Aug 18, 2022 at 15:08
  • Always, provide at least 20 lines in a stacktrace Commented Aug 19, 2022 at 10:37

1 Answer 1

1

By looks of your docker-compose , you have wrongly used SPRING_DATASOURCE_DRIVER_CLASS_NAME.

it should be

SPRING_DATASOURCE_DRIVER_CLASS_NAME = com.mysql.jdbc.Driver
SPRING_DATASOURCE_DIALECT = org.hibernate.dialect.MySQL8Dialect 
Sign up to request clarification or add additional context in comments.

1 Comment

@qwercan, I mean, if you refer my answer above which I have updated, can you please let me know if you are still getting this error: Caused by: java.lang.RuntimeException: Failed to instantiate class java.sql.Driver java.lang.NoSuchMethodException: java.sql.Driver.<init>()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.