Netflix尤里卡客户端微服务未向尤里卡服务器注册

时间:2019-06-08 08:27:18

标签: java spring-boot netflix-eureka

我正在尝试在eureka服务器上注册我的微服务。但是它显示浏览器中没有可用的实例。我在控制台中没有收到任何错误。请帮助我解决这个问题。

我已经通过在Google上搜索尝试了多个选项。不过,我仍然无法解决问题。

微服务application.properties

  spring.application.name=jecreations-core
  eureka.client.serviceUrl.defaultZone=http://localhost:8761/eureka/
  eureka.client.register-with-eureka=true

客户端主类

 @EnableEurekaClient
 @SpringBootApplication
 @EnableConfigurationProperties(ImageProperties.class)
 public class JecreationsApplication extends SpringBootServletInitializer{
public static void main(String[] args) {
    SpringApplication.run(JecreationsApplication.class, args);
}
 }

Eureka Server application.properties

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

Eureka服务器主类。

 @SpringBootApplication
 @EnableEurekaServer
 public class JeeurekaApplication extends SpringBootServletInitializer{

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

}

3 个答案:

答案 0 :(得分:0)

您需要使用

注释eureka服务器主类
@SpringBootApplication
@EnableEurekaServer
@EnableDiscoveryClient

public class EurekaServerApplication {

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

此外,您还需要使用以下注释来注释客户的主类:

@SpringBootApplication
@EnableDiscoveryClient
public class MicroApplication {

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

您需要在eureka客户端的application.yml中进行以下配置:

eureka:
  client:
    serviceUrl:
      defaultZone: http://localhost:8761/eureka/

在Eureka Server application.yml文件中,我具有以下配置:

info:
  component: Eureka Server

server: 
  port: 8761


eureka:
  client:
    registerWithEureka: false
    fetchRegistry: false
  server:
    enable-self-preservation: false
    waitTimeInMsWhenSyncEmpty: 0
  instance:
    hostname: localhost
    lease-expiration-duration-in-seconds: 15
    lease-renewal-interval-in-seconds: 5

答案 1 :(得分:0)

尝试这样

eureka服务器配置

eureka.client.registerWithEureka= false
eureka.client.serviceUrl.defaultZone= ${EUREKA_URI:http://localhost:8761/eureka}

eureka客户端配置

eureka.client.serviceUrl.defaultZone= http://localhost:8761/eureka
eureka.instance.preferIpAddress= true

仍然面对问题,请关注我的仓库 https://github.com/vimaleshJeyavelmani/spring-boot-micros

谢谢,
维玛列什

答案 2 :(得分:0)

问题在于eureka客户端的依赖性。 我已经赋予了这种依赖性

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

代替

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

感谢您的答复。