Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/spring-boot/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring boot spring cloud随机端口未注册到Eureka_Spring Boot_Spring Cloud - Fatal编程技术网

Spring boot spring cloud随机端口未注册到Eureka

Spring boot spring cloud随机端口未注册到Eureka,spring-boot,spring-cloud,Spring Boot,Spring Cloud,我正试图让我的微服务在随机端口上运行。如果按照中的建议在服务bootstrap.yml中指定server.port:0,则会得到以下NPE: 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\ma

我正试图让我的微服务在随机端口上运行。如果按照中的建议在服务bootstrap.yml中指定server.port:0,则会得到以下NPE:

    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中删除server.port并将其放在配置服务器内的fii-rest-mocker.yml中,那么我的服务将在随机端口上启动,但在Eureka的8080上注册

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

那么,如何让服务在随机端口上引导并在Eureka中注册呢


我正在使用spring cloud的1.0.0.RELEASE版本和spring boot的1.2.2.RELEASE版本。

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

@spencergib:奇怪,你说它现在不应该工作

我(显然)通过强制属性
eureka.instance.non-secure port
为0而不是默认的80来使它工作

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


我错过了什么吗?

现在(Spring boot 1.5.10和Edgeware.SR2),您可以使用随机端口,但不能设置管理端口。这将触发一个bug,其中应用程序使用管理端口注册,但该端口不起作用)

尝试为每个正在运行的实例注册一个唯一的实例名称。默认(非唯一)实例名称将仅替换正在运行的实例

这可以通过设置以下属性来实现:

eureka.instance.instance-id=${spring.application.name}:${spring.application.instance_id:${random.value}}

可能不会。我们并没有那么努力地让它工作。可能是一个使用配置示例更新文档的请求?
containerPortInitializer()
是一个SpringCloud功能,它提供了对随机端口号的支持。如果默认的EurekaClientInstanceConfigBean没有在默认情况下将
非安全端口设置为80,那么它将透明地工作。为什么不将其更改为0?我知道您正在为Spring Boot添加一些很酷的功能,但这是一个严重的问题,尚未解决(v2.1.2.RELEASE)
eureka.instance.instance-id=${spring.application.name}:${spring.application.instance_id:${random.value}}