4
respostas

Microservice nao conecta no Serve Eureka

Para quem fez tudo certo e mesmo assim o microservice nao é registrado no eureka e nao é informado nenhum erro provavelmente sao as depreciaçoes das importaçoes.

Segue importançoes e Anotaçloes funcionais ate esta data.

Do service :

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;

@SpringBootApplication
@EnableDiscoveryClient
public class PagamentoApplication {

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

}
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/alura-microservices?createDatabaseIfNotExist=true
spring.datasource.username=root
spring.datasource.password=123456789
spring.jpa.show-sql=true


eureka.client.register-with-eureka=true
eureka.client.fetch-registry=true
spring.application.name=pagamentos-ms
eureka.client.serviceUrl.defaultZone=http://localhost:8761/eureka
<dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
            <version>4.1.0</version>
        </dependency>

Do eureka

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;

@SpringBootApplication
@EnableEurekaServer
public class ServerApplication {

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

}
server.port=8761

spring.application.name=server
eureka.client.register-with-eureka=false
eureka.client.fetch-registry=false

eureka.client.serviceUrl.defaultZone=http://localhost:8761/eureka
<properties>
        <java.version>17</java.version>
        <spring-cloud.version>2023.0.0</spring-cloud.version>
</properties>

<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>
4 respostas

Oii, tudo bem? Espero que sim!

Agradeço sua contribuição com o fórum! Continue se dedicando aos estudos e colocando em prática seus aprendizados.

Caso surjam dúvidas, fico à disposição.

Abraços e bons estudos

Representou, Girleno! Valeu!

Muito obrigado!!!

Meu eureka server não estava reconhecendo o cliente. No entanto, só não estava exibindo no serviço de monitoramento, mas estava gerando uma porta para o microsserviço. Estava usando como client a seguinte dependência: org.springframework.cloud spring-cloud-starter-netflix-eureka-client 4.1.1

Então verifiquei que colocando os seguint import: import org.springframework.cloud.client.discovery.EnableDiscoveryClient;

e colocando a anottation @EnableDiscoveryClient em cima da classe da aplicação, funcionou redondo.

Então na versão 4.1.1 se usa agora é a esse anotation e não @EnableEurekaClient.

Quer mergulhar em tecnologia e aprendizagem?

Receba a newsletter que o nosso CEO escreve pessoalmente, com insights do mercado de trabalho, ciência e desenvolvimento de software