Search code examples
spring-bootnetflix-eureka

I'm having problems with springboot 3.0.0 it doesn't recognize my eureka server and client


I have problems with springboot 3.0.0 it doesn't recognize my eureka server and client but in version 2.7.4 it works normally was there any change?

follow my classes:

api-gateway:

@SpringBootApplication
@EnableEurekaServer
public class ApiGatewayApplication {
    public static void main(String[] args) {
        SpringApplication.run(ApiGatewayApplication.class, args);
    }

}

application.properties:

spring.application.name = api-gateway
server.port = 8761
eureka.client.register-with-eureka = false
eureka.client.fetch-registry = false
eureka.instance.hostname=localhost
eureka.client.serviceUrl.defaultZone=http://localhost:8761/eureka/

My routing:

@EnableDiscoveryClient
@SpringBootApplication
public class RoutingApplication {

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

}

application.properties:

server.port=8080
spring.application.name=routing
eureka.client.serviceUrl.defaultZone=http://localhost:8761/eureka/
eureka.instance.hostname=localhost
spring.cloud.gateway.discovery.locator.enabled=true

#spring.main.web-application-type=reactive
spring.cloud.gateway.enabled=true
spring.cloud.gateway.routes[0].id=user
spring.cloud.gateway.routes[0].uri=lb://USER
spring.cloud.gateway.routes[0].predicates=Path=/user/**

spring.cloud.gateway.routes[1].id=testes
spring.cloud.gateway.routes[1].uri=lb://TESTES
spring.cloud.gateway.routes[1].predicates=Path=/testes/**

spring.cloud.gateway.routes[2].id=user-create
spring.cloud.gateway.routes[2].uri=lb://USER-CREATE
spring.cloud.gateway.routes[2].predicates=Path=/user-create/**

spring.cloud.gateway.routes[3].id=category-product
spring.cloud.gateway.routes[3].uri=lb://CATEGORY-PRODUCT
spring.cloud.gateway.routes[3].predicates=Path=/category-product/**

My category-product

@EnableDiscoveryClient
@SpringBootApplication
public class CategoryProductApplication {

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

}

My controller:

@RestController
@RequestMapping("/category-product")
public class CategoryProductContriller {


  @GetMapping("/item")
  public String itens()
  {
    return "Testar";
  }

}

application.properties

    server.port = 8001
    spring.application.name = category-product
    eureka.client.serviceUrl.defaultZone = http://localhost:8761/eureka

eureka.instance.hostname=localhost

Solution

  • same problems and the following changes worked for me.

    On server side,in the pom.xml make these changes (spring-cloud-starter-netflix-eureka-server):

    <properties>
        <java.version>17</java.version>
        <spring-cloud.version>2022.0.0-RC2</spring-cloud.version>
    </properties>
    ...   
    <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>
    ...
    <repositories>
        <repository>
            <id>netflix-candidates</id>
            <name>Netflix Candidates</name>
            <url>https://artifactory-oss.prod.netflix.net/artifactory/maven-oss-candidates</url>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </repository>
        <repository>
            <id>spring-milestones</id>
            <name>Spring Milestones</name>
            <url>https://repo.spring.io/milestone</url>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </repository>
    </repositories>
    

    Same changes on client side (spring-cloud-starter-netflix-eureka-client) but in addition you have remove @EnableEurekaClient in *Application.java because import org.springframework.cloud.netflix.eureka.EnableEurekaClient is not longer avaible.

    I solved the problem by creating a new project from Spring Initializr and watching the dependecies in the pom.xml. Currently I couldn't find any documentation about it.