首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >spring-cloud随机端口未注册到Eureka

spring-cloud随机端口未注册到Eureka
EN

Stack Overflow用户
提问于 2015-04-15 05:00:20
回答 4查看 4.5K关注 0票数 6

我正在尝试让我的微服务出现在随机端口上。如果我按照Spring Cloud app doesn't register correct port to Eureka中的建议在服务bootstrap.yml中指定server.port: 0,我会得到以下NPE:

代码语言:javascript
复制
    2015-04-14 16:24:34,357  INFO          com.fisc.restmocker.Application:  47 - Starting Application on JSR-IAAS-20 with PID 4820 (C:\iaas2.0\git\FII-RestMocker\build\classes\main started by jsr in C:\iaas2.0\git\FII-RestMocker)
    2015-04-14 16:24:34,482  INFO ation.AnnotationConfigApplicationContext: 510 - Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@4fb61f4a: startup date [Tue Apr 14 16:24:34 EDT 2015]; root of context hierarchy
    2015-04-14 16:24:34,748  INFO ion.AutowiredAnnotationBeanPostProcessor: 153 - JSR-330 'javax.inject.Inject' annotation found and supported for autowiring
    2015-04-14 16:24:35,217  WARN ix.config.sources.URLConfigurationSource: 120 - No URLs will be polled as dynamic configuration sources.
    2015-04-14 16:24:35,560  INFO ontext.support.DefaultLifecycleProcessor: 341 - Starting beans in phase 0
    2015-04-14 16:24:35,560  INFO lientConfigServiceBootstrapConfiguration:  92 - Locating configserver via discovery
    2015-04-14 16:24:35,592  WARN lientConfigServiceBootstrapConfiguration: 113 - Could not locate configserver via discovery
    java.lang.NullPointerException: null
        at com.netflix.discovery.DiscoveryClient$$FastClassBySpringCGLIB$$a84c8cb4.invoke(<generated>) ~[spring-core-4.1.5.RELEASE.jar:1.1.147]
        at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204) ~[spring-core-4.1.5.RELEASE.jar:4.1.5.RELEASE]
        at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:717) ~[spring-aop-4.1.5.RELEASE.jar:4.1.5.RELEASE]
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157) ~[spring-aop-4.1.5.RELEASE.jar:4.1.5.RELEASE]
        at org.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:133) ~[spring-aop-4.1.5.RELEASE.jar:4.1.5.RELEASE]
        at org.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:121) ~[spring-aop-4.1.5.RELEASE.jar:4.1.5.RELEASE]
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.1.5.RELEASE.jar:4.1.5.RELEASE]
        at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:653) ~[spring-aop-4.1.5.RELEASE.jar:4.1.5.RELEASE]
        at com.netflix.discovery.DiscoveryClient$$EnhancerBySpringCGLIB$$96b726d7.getNextServerFromEureka(<generated>) ~[spring-core-4.1.5.RELEASE.jar:1.1.147]
        at org.springframework.cloud.netflix.config.DiscoveryClientConfigServiceBootstrapConfiguration.refresh(DiscoveryClientConfigServiceBootstrapConfiguration.java:93) [spring-cloud-netflix-core-1.0.0.RELEASE.jar:1.0.0.RELEASE]
        at org.springframework.cloud.netflix.config.DiscoveryClientConfigServiceBootstrapConfiguration.onApplicationEvent(DiscoveryClientConfigServiceBootstrapConfiguration.java:65) [spring-cloud-netflix-core-1.0.0.RELEASE.jar:1.0.0.RELEASE]
        at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:151) [spring-context-4.1.5.RELEASE.jar:4.1.5.RELEASE]
        at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:128) [spring-context-4.1.5.RELEASE.jar:4.1.5.RELEASE]
        at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:331) [spring-context-4.1.5.RELEASE.jar:4.1.5.RELEASE]
        at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:773) [spring-context-4.1.5.RELEASE.jar:4.1.5.RELEASE]
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:483) [spring-context-4.1.5.RELEASE.jar:4.1.5.RELEASE]
        at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:686) [spring-boot-1.2.2.RELEASE.jar:1.2.2.RELEASE]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:320) [spring-boot-1.2.2.RELEASE.jar:1.2.2.RELEASE]
        at org.springframework.boot.builder.SpringApplicationBuilder.run(SpringApplicationBuilder.java:139) [spring-boot-1.2.2.RELEASE.jar:1.2.2.RELEASE]
        at org.springframework.cloud.bootstrap.BootstrapApplicationListener.bootstrapServiceContext(BootstrapApplicationListener.java:125) [spring-cloud-config-client-1.0.0.RELEASE.jar:1.0.0.RELEASE]
        at org.springframework.cloud.bootstrap.BootstrapApplicationListener.onApplicationEvent(BootstrapApplicationListener.java:75) [spring-cloud-config-client-1.0.0.RELEASE.jar:1.0.0.RELEASE]
        at org.springframework.cloud.bootstrap.BootstrapApplicationListener.onApplicationEvent(BootstrapApplicationListener.java:1) [spring-cloud-config-client-1.0.0.RELEASE.jar:1.0.0.RELEASE]
        at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:151) [spring-context-4.1.5.RELEASE.jar:4.1.5.RELEASE]
        at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:128) [spring-context-4.1.5.RELEASE.jar:4.1.5.RELEASE]
        at org.springframework.boot.context.event.EventPublishingRunListener.publishEvent(EventPublishingRunListener.java:100) [spring-boot-1.2.2.RELEASE.jar:1.2.2.RELEASE]
        at org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:59) [spring-boot-1.2.2.RELEASE.jar:1.2.2.RELEASE]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:285) [spring-boot-1.2.2.RELEASE.jar:1.2.2.RELEASE]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:957) [spring-boot-1.2.2.RELEASE.jar:1.2.2.RELEASE]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:946) [spring-boot-1.2.2.RELEASE.jar:1.2.2.RELEASE]
        at com.fisc.restmocker.Application.main(Application.java:18) [main/:na]
    2015-04-14 16:24:35,592  INFO          com.fisc.restmocker.Application:  56 - Started Application in 1.641 seconds (JVM running for 2.978)

下面是bootstrap.yml:

代码语言:javascript
复制
    info:
      description: FII user interface mock service

    spring:
      application:
        name: FII-rest-mocker
      cloud:
        config:
          failFast: true
          discovery:
            enabled: true
            serviceId: config-server
          username: user
          password: password

    logging:
      level:
        com.netflix.discovery: 'OFF'
        org.springframework.cloud: 'DEBUG'

    eureka:
      instance:
        leaseRenewalIntervalInSeconds: 10
        metadataMap:
          instanceId: ${spring.application.name}:${spring.application.instance_id:${random.value}}
      client:
        serviceUrl:
          defaultZone: ${vcap.services.${PREFIX:}eureka.credentials.uri:http://user:password@localhost:8761}/eureka/

    server:
      port: 0

如果我从bootstrap.yml中删除server.port,并将其放在配置服务器内的fii-rest-mocker.yml中,那么我的服务将在一个随机端口上启动,但在Eureka中注册在8080上。

我只运行一台Eureka服务器和一台Config服务器。所有服务都在同一台计算机上运行。

那么,如何在Eureka的随机端口上启动和注册服务呢?

我使用的是spring-cloud的1.0.0.RELEASE版本和spring-boot的1.2.2.RELEASE版本。

EN

回答 4

Stack Overflow用户

发布于 2015-04-15 05:41:05

随机端口目前与spring.cloud.config.discovery.enabled: true不兼容。

票数 4
EN

Stack Overflow用户

发布于 2015-04-15 21:14:43

@spencergibb:奇怪的是,你说它目前不应该工作。

我设法让它工作(显然)是通过强制将属性eureka.instance.non-secure-port设置为0而不是默认的80。

将此值设置为零将触发EurekaDiscoveryClientConfiguration.containerPortInitializer()的执行,它将从嵌入式servlet容器中检索实际的端口号。

我错过了什么吗?

票数 3
EN

Stack Overflow用户

发布于 2018-02-17 23:47:16

现在(Spring boot 1.5.10和Edgeware.SR2),您只能使用随机端口,但不能设置管理端口。这会在应用程序注册到无法工作的管理端口时触发bug )

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/29637324

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档