0
votes

I try to connect my service (auth-service) to the Eureka Server for the service registry. The Eureka server is running, but when I try to connect the auth-service nothing happens.

I added the configurations to application.yaml and application.properties, but nothing helped.

application.yaml from auth-service:

eureka:
      client:
        fetchRegistry: true
        registryFetchIntervalSeconds: 5
        serviceUrl:
          defaultZone: http://localhost:8761/eureka
      instance:
        preferIpAddress: true

URL of Eureka server: http://localhost:8761/

DS Replicas: localhost

Message when I start auth-service:

2019-05-24 16:58:11.457  INFO [auth-service,,,] 14704 --- [           main] o.s.s.concurrent.ThreadPoolTaskExecutor  : Initializing ExecutorService 'applicationTaskExecutor'
2019-05-24 16:58:13.293  INFO [auth-service,,,] 14704 --- [           main] o.s.cloud.commons.util.InetUtils         : Cannot determine local hostname
2019-05-24 16:58:14.521  INFO [auth-service,,,] 14704 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8080 (http) with context path ''
2019-05-24 16:58:14.524  INFO [auth-service,,,] 14704 --- [           main] d.h.authservice.AuthServiceApplication   : Started AuthServiceApplication in 11.448 seconds (JVM running for 12.63)

The Eureka Server is annotated with @EnableEurekaServer and the Client is annotated with @EnableDiscoveryClient

auth-service pom:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.1.4.RELEASE</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>de.hspf</groupId>
<artifactId>auth-service</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>auth-service</name>
<description>Demo project for Spring Boot</description>

<properties>
    <java.version>1.8</java.version>
    <spring-cloud.version>Greenwich.RELEASE</spring-cloud.version>
</properties>

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.postgresql</groupId>
        <artifactId>postgresql</artifactId>
        <version>42.2.5</version>
    </dependency>
    <dependency>
        <groupId>org.hibernate.javax.persistence</groupId>
        <artifactId>hibernate-jpa-2.0-api</artifactId>
        <version>1.0.1.Final</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-security</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-test</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>com.sendgrid</groupId>
        <artifactId>sendgrid-java</artifactId>
        <version>4.1.2</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-thymeleaf</artifactId>
    </dependency>
    <dependency>
        <groupId>io.jsonwebtoken</groupId>
        <artifactId>jjwt</artifactId>
        <version>0.9.1</version>
    </dependency>
    <dependency>
        <groupId>org.modelmapper</groupId>
        <artifactId>modelmapper</artifactId>
        <version>1.1.0</version>
    </dependency>
    <dependency>
        <groupId>org.thymeleaf</groupId>
        <artifactId>thymeleaf-spring3</artifactId>
        <version>3.0.8.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.xmlunit</groupId>
        <artifactId>xmlunit-core</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-sleuth-zipkin</artifactId>
        <version>2.1.1.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-netflix-eureka-client</artifactId>
        <version>2.0.1.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-netflix-eureka-starter</artifactId>
    </dependency>
</dependencies>

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-dependencies</artifactId>
            <version>Finchley.M9</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>

Discovery Service pom

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.example</groupId>
<artifactId>discovery-server</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>

<name>discovery-server</name>

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.1.2.RELEASE</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <java.version>1.8</java.version>
    <spring-cloud.version>Greenwich.RELEASE</spring-cloud.version>
</properties>

<dependencies>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-actuator</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>Finchley.M9</version>

            <type>pom</type>

            <scope>import</scope>

        </dependency>

    </dependencies>

</dependencyManagement>

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>

<repositories>
    <repository>
        <id>spring-milestones</id>
        <name>Spring Milestones</name>
        <url>https://repo.spring.io/milestone</url>
        <snapshots>
            <enabled>false</enabled>
        </snapshots>
    </repository>
</repositories>

5
What's versions are you using? Can you post dependencies (build files)?spencergibb
I just added the pom files of the discovery server and auth-servicesoftwareUser
While you have spring-cloud.version, you aren't using that property and setting the version to <version>Finchley.M9</version> which is an unsupported milestone. Please change it to Greenwich.SR1 (the latest) and update boot to 2.1.5 and try again.spencergibb
I changed the version settings in the properties section and the dependency management to Greenwich.SR1 and Spring boot to 2.1.5, but still nothing happens. The Eureka Server is running but not showing any registered service.softwareUser

5 Answers

0
votes

Try to use this dependency for client

<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>

instead of

<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-netflix-eureka-client</artifactId>
    <version>2.0.1.RELEASE</version>
</dependency>
<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-netflix-eureka-starter</artifactId>
</dependency>
1
votes

Default settings should be : server.port=8761

eureka.client.register-with-eureka=false eureka.client.fetch-registry=false

logging.level.com.netflix.eureka=OFF logging.level.com.netflix.discovery=OFF

As suggested by the official site. Also, Don't forget to add @EnableEurekaServer in your main file Source: https://spring.io/guides/gs/service-registration-and-discovery/

0
votes

In the auth-service application.yaml is missing: registerWithEureka: true

eureka:
      client:
        registerWithEureka: true
        fetchRegistry: true
        registryFetchIntervalSeconds: 5
        serviceUrl:
          defaultZone: http://localhost:8761/eureka
      instance:
        preferIpAddress: true

You just put the fetchRegistry: true, which is used to record information on the client obtained from the server, to find other microservices, but not to register the client.

0
votes

I am having this same issue as well.

My eureka service works.

  1. added eureka server dependency.
 <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
  </dependency>
  1. added @EnableEurekaServer annotation on @SpringBootApplication.
@SpringBootApplication
@EnableEurekaServer
public class EurekaserverApplication {
    public static void main(String[] args) {
        SpringApplication.run(EurekaserverApplication.class, args);
        System.out.println("Eureka! It's working!");
    }
}
  1. Added application properties :
server.port=8761.   
eureka.client.register-with-eureka=false eureka.client.fetch-registry=false

For my Microservice :

  1. added eureka discovery client dependency
<dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
            <version>2.2.5.RELEASE</version>
</dependency>
  1. added annotation @EnableEurekaClient to @SpringBootApplication
@SpringBootApplication
@EnableEurekaClient
public class CouponApp {
    public static void main(String[] args) {
        SpringApplication.run(CouponApp.class, args);
        System.out.println("spring cloud works!");
    }
}
  1. added application.properties
spring.application.name=coupon-service
eureka.client.service-url.defaultZone=http://localhost:8761/eureka

Here is my error :

com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure

The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.

Any pointers or did I miss some configuration?

0
votes

You should add / after : http://localhost:8761/eureka for client & server.

http://localhost:8761/eureka/