Spring - 服务被尤里卡服务器发现后关闭 [英] Spring - service shuts down after being discovered by eureka server

查看:64
本文介绍了Spring - 服务被尤里卡服务器发现后关闭的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的服务app-name"在启动后立即意外关闭.那个时候

My service "app-name" shuts down unexpectedly right after having started. At that time

  • eureka 服务器运行在 8761 端口
  • 服务已被eureka服务器成功发现(注册状态:204向eureka注册应用,状态为UP)
  • 发现的应用已在端口 9100 上完全启动(在 7.427 秒内启动 (JVM 运行 7.999)

如果我不包括服务发现,应用程序启动正常

If I don't include service discovery the app starts up fine

这里是java实现

//Eureka server
@SpringBootApplication
@EnableEurekaServer
public class EurekaServerApplication {

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

//Discovered service
@SpringBootApplication
@EnableDiscoveryClient
public class Application {

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

application.properties(或bootstrap.properties)

# properties for discovered service
spring.application.name=<app-name>
spring.profiles.active=default
spring.cloud.config.uri=http://localhost:8888
server.port=9100
eureka.client.service-url.default-zone=http://localhost:8761/eureka

# properties for eureka
spring.application.name=symphony-nlp-eureka-server
server.port=8761
eureka.client.register-with-eureka=false
eureka.client.fetch-registry=false

这是日志

来自发现的服务的日志

// Service LOGS
2018-01-30 09:25:17.222 INFO  [restartedMain] [ConfigServicePropertySourceLocator] Fetching config from server at: http://localhost:8888
2018-01-30 09:25:17.387 INFO  [restartedMain] [ConfigServicePropertySourceLocator] Located environment: name=<app-name>, profiles=[default], label=null, version=null, state=null
2018-01-30 09:25:17.387 INFO  [restartedMain] [PropertySourceBootstrapConfiguration] Located property source: CompositePropertySource {name='configService', propertySources=[MapPropertySource {name='classpath:/<app-name>.yml'}]}
2018-01-30 09:25:17.394 INFO  [restartedMain] [<app-name>] The following profiles are active: default
2018-01-30 09:25:17.405 INFO  [restartedMain] [AnnotationConfigServletWebServerApplicationContext] Refreshing org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@14f7cee: startup date [Tue Jan 30 09:25:17 GMT 2018]; parent: org.springframework.context.annotation.AnnotationConfigApplicationContext@121507b
2018-01-30 09:25:18.802 INFO  [restartedMain] [DefaultListableBeanFactory] Overriding bean definition for bean 'environmentWebEndpointExtension' with a different definition: replacing [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=org.springframework.boot.actuate.autoconfigure.env.EnvironmentEndpointAutoConfiguration; factoryMethodName=environmentWebEndpointExtension; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [org/springframework/boot/actuate/autoconfigure/env/EnvironmentEndpointAutoConfiguration.class]] with [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=org.springframework.cloud.autoconfigure.LifecycleMvcEndpointAutoConfiguration; factoryMethodName=environmentWebEndpointExtension; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [org/springframework/cloud/autoconfigure/LifecycleMvcEndpointAutoConfiguration.class]]
2018-01-30 09:25:19.020 INFO  [restartedMain] [GenericScope] BeanFactory id=270e5605-a6fb-3ddf-90f9-1ab7f8277113
2018-01-30 09:25:19.031 INFO  [restartedMain] [AutowiredAnnotationBeanPostProcessor] JSR-330 'javax.inject.Inject' annotation found and supported for autowiring
2018-01-30 09:25:19.062 INFO  [restartedMain] [PostProcessorRegistrationDelegate$BeanPostProcessorChecker] Bean 'org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration' of type [org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration$$EnhancerBySpringCGLIB$$69f84f5b] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2018-01-30 09:25:19.118 INFO  [restartedMain] [ValidatorFactoryImpl] HV000238: Temporal validation tolerance set to 0.
2018-01-30 09:25:19.437 INFO  [restartedMain] [TomcatWebServer] Tomcat initialized with port(s): 9100 (http)
2018-01-30 09:25:19.447 INFO  [restartedMain] [StandardService] Starting service [Tomcat]
2018-01-30 09:25:19.447 INFO  [restartedMain] [StandardEngine] Starting Servlet Engine: Apache Tomcat/8.5.23
2018-01-30 09:25:19.454 INFO  [localhost-startStop-1] [AprLifecycleListener] The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: <listing the java path>
2018-01-30 09:25:19.575 INFO  [localhost-startStop-1] [[/]] Initializing Spring embedded WebApplicationContext
2018-01-30 09:25:19.576 INFO  [localhost-startStop-1] [ContextLoader] Root WebApplicationContext: initialization completed in 2171 ms
2018-01-30 09:25:19.903 INFO  [localhost-startStop-1] [RequestMappingHandlerMapping] Mapped "{[/error]}" onto public org.springframework.http.ResponseEntity<java.util.Map<java.lang.String, java.lang.Object>> org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController.error(javax.servlet.http.HttpServletRequest)
2018-01-30 09:25:19.903 INFO  [localhost-startStop-1] [RequestMappingHandlerMapping] Mapped "{[/error],produces=[text/html]}" onto public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)
2018-01-30 09:25:19.969 INFO  [localhost-startStop-1] [SimpleUrlHandlerMapping] Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2018-01-30 09:25:19.969 INFO  [localhost-startStop-1] [SimpleUrlHandlerMapping] Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2018-01-30 09:25:19.998 INFO  [localhost-startStop-1] [SimpleUrlHandlerMapping] Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2018-01-30 09:25:20.742 INFO  [localhost-startStop-1] [WebMvcEndpointHandlerMapping] Mapped "{[/actuator/health],methods=[GET],produces=[application/vnd.spring-boot.actuator.v2+json || application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.web.servlet.WebMvcEndpointHandlerMapping$OperationHandler.handle(javax.servlet.http.HttpServletRequest,java.util.Map<java.lang.String, java.lang.String>)
2018-01-30 09:25:20.743 INFO  [localhost-startStop-1] [WebMvcEndpointHandlerMapping] Mapped "{[/actuator/info],methods=[GET],produces=[application/vnd.spring-boot.actuator.v2+json || application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.web.servlet.WebMvcEndpointHandlerMapping$OperationHandler.handle(javax.servlet.http.HttpServletRequest,java.util.Map<java.lang.String, java.lang.String>)
2018-01-30 09:25:20.743 INFO  [localhost-startStop-1] [WebMvcEndpointHandlerMapping] Mapped "{[/actuator],methods=[GET],produces=[application/vnd.spring-boot.actuator.v2+json || application/json]}" onto private java.util.Map<java.lang.String, java.util.Map<java.lang.String, org.springframework.boot.actuate.endpoint.web.Link>> org.springframework.boot.actuate.endpoint.web.servlet.WebMvcEndpointHandlerMapping.links(javax.servlet.http.HttpServletRequest)
2018-01-30 09:25:20.805 INFO  [localhost-startStop-1] [ServletRegistrationBean] Mapping servlet: 'dispatcherServlet' to [/]
2018-01-30 09:25:20.809 INFO  [localhost-startStop-1] [FilterRegistrationBean] Mapping filter: 'webMetricsFilter' to: [/*]
2018-01-30 09:25:20.809 INFO  [localhost-startStop-1] [FilterRegistrationBean] Mapping filter: 'characterEncodingFilter' to: [/*]
2018-01-30 09:25:20.809 INFO  [localhost-startStop-1] [FilterRegistrationBean] Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2018-01-30 09:25:20.810 INFO  [localhost-startStop-1] [FilterRegistrationBean] Mapping filter: 'httpPutFormContentFilter' to: [/*]
2018-01-30 09:25:20.810 INFO  [localhost-startStop-1] [FilterRegistrationBean] Mapping filter: 'requestContextFilter' to: [/*]
2018-01-30 09:25:20.810 INFO  [localhost-startStop-1] [FilterRegistrationBean] Mapping filter: 'webRequestLoggingFilter' to: [/*]
2018-01-30 09:25:20.838 INFO  [restartedMain] [MessageBroker] creating message broker
2018-01-30 09:25:22.197 INFO  [restartedMain] [Authentication] Successfully retrieved tokens
2018-01-30 09:25:22.399 WARN  [restartedMain] [URLConfigurationSource] No URLs will be polled as dynamic configuration sources.
2018-01-30 09:25:22.399 INFO  [restartedMain] [URLConfigurationSource] To enable URLs as dynamic configuration sources, define System property archaius.configurationSource.additionalUrls or make config.properties available on classpath.
2018-01-30 09:25:22.404 WARN  [restartedMain] [URLConfigurationSource] No URLs will be polled as dynamic configuration sources.
2018-01-30 09:25:22.404 INFO  [restartedMain] [URLConfigurationSource] To enable URLs as dynamic configuration sources, define System property archaius.configurationSource.additionalUrls or make config.properties available on classpath.
2018-01-30 09:25:22.445 INFO  [restartedMain] [ValidatorFactoryImpl] HV000238: Temporal validation tolerance set to 0.
2018-01-30 09:25:22.518 INFO  [restartedMain] [RequestMappingHandlerAdapter] Looking for @ControllerAdvice: org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@14f7cee: startup date [Tue Jan 30 09:25:17 GMT 2018]; parent: org.springframework.context.annotation.AnnotationConfigApplicationContext@121507b
2018-01-30 09:25:22.818 WARN  [restartedMain] [OptionalLiveReloadServer] Unable to start LiveReload server
2018-01-30 09:25:23.020 INFO  [restartedMain] [AnnotationMBeanExporter] Registering beans for JMX exposure on startup
2018-01-30 09:25:23.028 INFO  [restartedMain] [AnnotationMBeanExporter] Bean with name 'configurationPropertiesRebinder' has been autodetected for JMX exposure
2018-01-30 09:25:23.029 INFO  [restartedMain] [AnnotationMBeanExporter] Bean with name 'environmentManager' has been autodetected for JMX exposure
2018-01-30 09:25:23.030 INFO  [restartedMain] [AnnotationMBeanExporter] Bean with name 'refreshScope' has been autodetected for JMX exposure
2018-01-30 09:25:23.031 INFO  [restartedMain] [AnnotationMBeanExporter] Located managed bean 'environmentManager': registering with JMX server as MBean [org.springframework.cloud.context.environment:name=environmentManager,type=EnvironmentManager]
2018-01-30 09:25:23.038 INFO  [restartedMain] [AnnotationMBeanExporter] Located managed bean 'refreshScope': registering with JMX server as MBean [org.springframework.cloud.context.scope.refresh:name=refreshScope,type=RefreshScope]
2018-01-30 09:25:23.048 INFO  [restartedMain] [AnnotationMBeanExporter] Located managed bean 'configurationPropertiesRebinder': registering with JMX server as MBean [org.springframework.cloud.context.properties:name=configurationPropertiesRebinder,context=14f7cee,type=ConfigurationPropertiesRebinder]
2018-01-30 09:25:23.088 INFO  [restartedMain] [DefaultLifecycleProcessor] Starting beans in phase 0
2018-01-30 09:25:23.094 INFO  [restartedMain] [InstanceInfoFactory] Setting initial instance status as: STARTING
2018-01-30 09:25:23.128 INFO  [restartedMain] [DiscoveryClient] Initializing Eureka in region us-east-1
2018-01-30 09:25:23.164 INFO  [restartedMain] [DiscoveryJerseyProvider] Using JSON encoding codec LegacyJacksonJson
2018-01-30 09:25:23.164 INFO  [restartedMain] [DiscoveryJerseyProvider] Using JSON decoding codec LegacyJacksonJson
2018-01-30 09:25:23.230 INFO  [restartedMain] [DiscoveryJerseyProvider] Using XML encoding codec XStreamXml
2018-01-30 09:25:23.230 INFO  [restartedMain] [DiscoveryJerseyProvider] Using XML decoding codec XStreamXml
2018-01-30 09:25:23.360 INFO  [restartedMain] [ConfigClusterResolver] Resolving eureka endpoints via configuration
2018-01-30 09:25:23.393 INFO  [restartedMain] [DiscoveryClient] Disable delta property : false
2018-01-30 09:25:23.393 INFO  [restartedMain] [DiscoveryClient] Single vip registry refresh property : null
2018-01-30 09:25:23.393 INFO  [restartedMain] [DiscoveryClient] Force full registry fetch : false
2018-01-30 09:25:23.393 INFO  [restartedMain] [DiscoveryClient] Application is null : false
2018-01-30 09:25:23.393 INFO  [restartedMain] [DiscoveryClient] Registered Applications size is zero : true
2018-01-30 09:25:23.393 INFO  [restartedMain] [DiscoveryClient] Application version is -1: true
2018-01-30 09:25:23.393 INFO  [restartedMain] [DiscoveryClient] Getting all instance registry info from the eureka server
2018-01-30 09:25:23.434 INFO  [restartedMain] [DiscoveryClient] The response status is 200
2018-01-30 09:25:23.435 INFO  [restartedMain] [DiscoveryClient] Starting heartbeat executor: renew interval is: 30
2018-01-30 09:25:23.436 INFO  [restartedMain] [InstanceInfoReplicator] InstanceInfoReplicator onDemand update allowed rate per min is 4
2018-01-30 09:25:23.439 INFO  [restartedMain] [DiscoveryClient] Discovery Client initialized at timestamp 1517304323439 with initial instances count: 0
2018-01-30 09:25:23.442 INFO  [restartedMain] [EurekaServiceRegistry] Registering application <app-name> with eureka with status UP
2018-01-30 09:18:53.450 INFO  [restartedMain] [Http11NioProtocol] Initializing ProtocolHandler ["http-nio-9100"]
2018-01-30 09:18:53.453 INFO  [DiscoveryClient-InstanceInfoReplicator-0] [DiscoveryClient] DiscoveryClient_<app-name>/<host>:<app-name>:9100 - registration status: 204

2018-01-30 09:18:53.457 INFO  [restartedMain] [Http11NioProtocol] Starting ProtocolHandler ["http-nio-9100"]
2018-01-30 09:18:53.464 INFO  [restartedMain] [NioSelectorPool] Using a shared selector for servlet write/read
2018-01-30 09:18:53.486 INFO  [restartedMain] [TomcatWebServer] Tomcat started on port(s): 9100 (http) with context path ''
2018-01-30 09:18:53.487 INFO  [restartedMain] [EurekaAutoServiceRegistration] Updating port to 9100
2018-01-30 09:18:53.490 INFO  [restartedMain] [<app-name>] Started <app-name> in 7.427 seconds (JVM running for 7.999)
2018-01-30 09:18:53.524 WARN  [restartedMain] [DiscoveryClient] Saw local status change event StatusChangeEvent [timestamp=1517303933524, current=DOWN, previous=UP]
2018-01-30 09:18:53.524 INFO  [DiscoveryClient-InstanceInfoReplicator-0] [DiscoveryClient] DiscoveryClient_<app-name>/<host>:<app-name>:9100: registering service...
2018-01-30 09:18:53.535 INFO  [restartedMain] [DiscoveryClient] Shutting down DiscoveryClient ...
2018-01-30 09:18:53.536 INFO  [restartedMain] [DiscoveryClient] Unregistering ...
2018-01-30 09:18:53.538 INFO  [DiscoveryClient-InstanceInfoReplicator-0] [DiscoveryClient] DiscoveryClient_<app-name>/<host>:<app-name>:9100 - registration status: 204
2018-01-30 09:18:53.542 INFO  [restartedMain] [DiscoveryClient] DiscoveryClient_<app-name>/<host>:<app-name>:9100 - deregister  status: 200
2018-01-30 09:18:53.549 INFO  [restartedMain] [DiscoveryClient] Completed shut down of DiscoveryClient

来自尤里卡服务器的日志

2018-01-30 09:18:15.373  INFO 10804 --- [nio-8761-exec-8] c.n.e.registry.AbstractInstanceRegistry  : Registered instance <app-name>/<host>:<app-name>:9100 with status UP (replication=false)
2018-01-30 09:18:15.383  INFO 10804 --- [nio-8761-exec-9] c.n.e.registry.AbstractInstanceRegistry  : Registered instance <app-name>/<host>:<app-name>:9100 with status DOWN (replication=false)
2018-01-30 09:18:15.400  INFO 10804 --- [io-8761-exec-10] c.n.e.registry.AbstractInstanceRegistry  : Cancelled instance <app-name>/<host>:<app-name>:9100 (replication=false)
2018-01-30 09:18:15.976  INFO 10804 --- [nio-8761-exec-2] c.n.e.registry.AbstractInstanceRegistry  : Registered instance <app-name>/<host>:<app-name>:9100 with status DOWN (replication=true)
2018-01-30 09:18:15.977  INFO 10804 --- [nio-8761-exec-2] c.n.e.registry.AbstractInstanceRegistry  : Cancelled instance <app-name>/<host>:<app-name>:9100 (replication=true)
2018-01-30 09:18:46.854  INFO 10804 --- [a-EvictionTimer] c.n.e.registry.AbstractInstanceRegistry  : Running the evict task with compensationTime 0ms

感谢您的帮助

推荐答案

我和你的配置一样,我也发现客户端关闭问题.添加

I have the same configuration as yours, I also get discovery client shutdown issue. Adding

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
</dependency> 

在 pom.xml 中修复了我的问题.

in pom.xml fixed my issue.

希望它也适用于您.但是我还在想为什么,在我按照spring cloud课程搭建应用的时候,课程作者没有专门添加'spring-boot-starter-web'.

Hope it works for you too. But I am still trying to figure out why, as I follow the spring cloud course to build the application, the course author don't add 'spring-boot-starter-web' specifically.

这篇关于Spring - 服务被尤里卡服务器发现后关闭的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆