0

I am trying to implement micro-service architecture for my spring project. So far the Eureka service is working fine and registering the GATEWAY & other required services. The problem is occurring in the GATEWAY service while accessing the other services through GATEWAY services.

Let's say our main service A is running on PORT 8080 and GATEWAY is running on PORT 8091. So we are using the URL: http://<IP_ADDRESS where deployed>:8091/crca/api/phoenix/users to access the service A on port 8080.

On hitting the above URL returns the below error:

error

I traced the error log and found that it is throwing java.net.UnknownHostException error. I saw many articles regarding this but found no perfect solution. I also followed this question as the error log was exact the same as this but nothing helped.

Error Log

error log

application.yml

server:
  port: 8091
  servlet:
    context-path: /crca/api
#eureka:
#  instance:
#    hostname: localhost
eureka:
  client:
    register-with-eureka: true
    fetch-registry: true
    service-url:
      defaultZone: http://<HOST_IP ADDRESS>:8099/server/crca/api/eureka  instance:
    hostname: <HOST_IP ADDRESS>
    prefer-ip-address: true
spring:
  application:
    name: api-gateway-service
  cloud:
    gateway:
      routes:
        - id: phoenix-service
          uri: lb://phoenix-service
          predicates:
            - Path=/crca/api/phoenix/**
        - id: statesville-service
          uri: lb://statesville-service
          predicates:
            - Path=/crca/api/statesville/**

pom.xml

<properties>
    <java.version>1.8</java.version>
    <spring-cloud.version>2020.0.4</spring-cloud.version>
</properties>
<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-actuator</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-gateway</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
        <version>2.2.7.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-circuitbreaker-reactor-resilience4j</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
</dependencies>
<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-dependencies</artifactId>
            <version>${spring-cloud.version}</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>
<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <version>${project.parent.version}</version>
        </plugin>
    </plugins>
</build>

The server used for deployment: IBM AS400 server

NOTE: The above solution is working fine locally by connecting to the DB2 database on the same server. This is not working only after deployment.

Avishek
  • 524
  • 16
  • 38

0 Answers0