Can we configure spring cloud gateway and service discovery (eureka server) on same SpringBootApplication

Viewed 278

I am trying to run Spring Cloud "Gateway" & "Eureka-Server" on the same @SpringBootApplication, below is my code :

Main Class:

@SpringBootApplication
@EnableEurekaServer
@EnableAdminServer
public class DemoGatewayApplication {

    public static void main(String[] args) {
        SpringApplication.run(DemoGatewayApplication .class, args);
    }

}

pom.xml

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-webflux</artifactId>
    </dependency>
    <dependency>
        <groupId>de.codecentric</groupId>
        <artifactId>spring-boot-admin-starter-server</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-eureka-server</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-sleuth</artifactId>
    </dependency>
</dependencies>

application.yml

server:
  port: ${GATEWAY_SERVER_PORT:8080}
             
eureka:
  instance:
    hostname: localhost
    appname: ${spring.application.name}
  client:
    enabled: true
    healthcheck:
      enabled: true
    fetch-registry: true
    register-with-eureka: true
    instance-info-replication-interval-seconds: 10
    registry-fetch-interval-seconds: 10
    service-url:
      defaultZone: http://${REGISTRY_SERVER_IP:localhost}:${REGISTRY_SERVER_PORT:8080}/eureka
   

When I run this application I am getting errors as below. I am not sure what is the issue or is it possible to have a gateway and eureka server on the same instance?

2021-09-13 18:10:12.411  INFO [gateway-service,,] 224 --- [nfoReplicator-0] com.netflix.discovery.DiscoveryClient    : DiscoveryClient_GATEWAY-SERVICE/gateway-service:9fd20bce350b1ccb477d53ad05e3504f - registration status: 404
2021-09-13 18:10:12.831  INFO [gateway-service,,] 224 --- [           main] o.s.cloud.commons.util.InetUtils         : Cannot determine local hostname
2021-09-13 18:10:13.979  INFO [gateway-service,,] 224 --- [           main] o.s.cloud.commons.util.InetUtils         : Cannot determine local hostname
2021-09-13 18:10:14.056  INFO [gateway-service,,] 224 --- [           main] c.n.gateway.DemoGatewayApplication    : Started DemoGatewayApplication in 27.56 seconds (JVM running for 29.713)
2021-09-13 18:10:15.459  INFO [gateway-service,,] 224 --- [tbeatExecutor-0] c.n.d.s.t.d.RedirectingEurekaHttpClient  : Request execution error. endpoint=DefaultEndpoint{ serviceUrl='http://localhost:8080/eureka/}
0 Answers
Related