【问题标题】:Spring Boot Application with Eureka on CloudFoundry healthcheck failed issue在 CloudFoundry 健康检查上使用 Eureka 的 Spring Boot 应用程序失败问题
【发布时间】:2016-06-21 18:09:17
【问题描述】:

我有一个 Spring Boot 应用程序(独立 jar 文件),我尝试将其部署在 CloudFoundry 上。我在 CloudFoundry 上创建了一个 Service Registry 实例,并尝试使用 CloudFoundry CLI 推送(cf push -p target\microservice-user-service-0.0.1-SNAPSHOT.jar) 我的应用程序(user-service)

成功上传应用,服务绑定也成功。一旦启动,它会给出健康检查失败的问题

2016-06-21T16:13:13.79-0400 [APP/0]      OUT 16: DEBUG StandardServletEnvironment - Initialized StandardServletEnvironment with PropertySources [servletConfigInitParams,servletContextInitParams,systemProperties,systemEnvironment]
    2016-06-21T16:13:13.79-0400 [APP/0]      OUT 16: DEBUG WebappClassLoaderBase -     findClass(java.lang.ObjectCustomizer)
    2016-06-21T16:13:13.79-0400 [APP/0]      OUT 16: DEBUG WebappClassLoaderBase -     --> Returning ClassNotFoundException
    2016-06-21T16:13:13.79-0400 [APP/0]      OUT 16: DEBUG WebappClassLoaderBase -     findClass(org.springframework.web.filter.GenericFilterBeanCustomizer)
    2016-06-21T16:13:13.79-0400 [APP/0]      OUT 16: DEBUG WebappClassLoaderBase -     --> Returning ClassNotFoundException
    2016-06-21T16:13:13.79-0400 [APP/0]      OUT 16: DEBUG WebappClassLoaderBase -     findClass(org.springframework.security.web.FilterChainProxyCustomizer)
    2016-06-21T16:13:13.79-0400 [APP/0]      OUT 16: DEBUG WebappClassLoaderBase -     --> Returning ClassNotFoundException
    2016-06-21T16:13:13.80-0400 [APP/0]      OUT 16: DEBUG DelegatingFilterProxy - Filter 'springSecurityFilterChain' configured successfully
    2016-06-21T16:13:13.80-0400 [APP/0]      OUT 16: DEBUG Registry - Managed= Tomcat:j2eeType=Filter,WebModule=//localhost/,name=springSecurityFilterChain,J2EEApplication=none,J2EEServer=none                                                                                                                                                2016-06-21T16:13:13.80-0400 [APP/0]      OUT 16: DEBUG BaseModelMBean - preRegister ApplicationFilterConfig[name=springSecurityFilterChain, filterClass=org.springframework.web.filter.DelegatingFilterProxy] Tomcat:j2eeType=Filter,WebModule=//localhost/,name=springSecurityFilterChain,J2EEApplication=none,J2EEServer=none
    2016-06-21T16:13:13.80-0400 [APP/0]      OUT 16: DEBUG [/] -  Starting filter 'webRequestLoggingFilter'                                                               2016-06-21T16:13:13.80-0400 [APP/0]      OUT 16: DEBUG Registry - Managed= Tomcat:j2eeType=Filter,WebModule=//localhost/,name=webRequestLoggingFilter,J2EEApplication=none,J2EEServer=none
    2016-06-21T16:13:13.80-0400 [APP/0]      OUT 16: DEBUG BaseModelMBean - preRegister ApplicationFilterConfig[name=webRequestLoggingFilter, filterClass=org.springframework.boot.actuate.trace.WebRequestTraceFilter] Tomcat:j2eeType=Filter,WebModule=//localhost/,name=webRequestLoggingFilter,J2EEApplication=none,J2EEServer=none
    2016-06-21T16:13:13.80-0400 [APP/0]      OUT 16: DEBUG StandardContext - Starting completed
    2016-06-21T16:13:13.80-0400 [APP/0]      OUT 16: DEBUG LifecycleBase - Setting state for [StandardEngine[Tomcat].StandardHost[localhost].StandardContext[]] to [STARTING]
    2016-06-21T16:13:13.80-0400 [APP/0]      OUT 16: DEBUG LifecycleBase - Setting state for [StandardEngine[Tomcat].StandardHost[localhost].StandardContext[]] to [STARTED]
    2016-06-21T16:13:13.80-0400 [APP/0]      OUT 16: DEBUG LifecycleBase - Setting state for [Pipeline[StandardEngine[Tomcat].StandardHost[localhost]]] to [INITIALIZING]
    2016-06-21T16:13:13.80-0400 [APP/0]      OUT 16: DEBUG LifecycleBase - Setting state for [Pipeline[StandardEngine[Tomcat].StandardHost[localhost]]] to [INITIALIZED]
    2016-06-21T16:13:13.80-0400 [APP/0]      OUT 16: DEBUG LifecycleBase - Setting state for [Pipeline[StandardEngine[Tomcat].StandardHost[localhost]]] to [STARTING_PREP]
    2016-06-21T16:13:13.80-0400 [APP/0]      OUT 16: DEBUG LifecycleBase - Setting state for [org.apache.catalina.valves.ErrorReportValve[localhost]] to [INITIALIZING]
    2016-06-21T16:13:13.80-0400 [APP/0]      OUT 16: DEBUG Registry - Managed= Tomcat:type=Valve,host=localhost,name=ErrorReportValve
    2016-06-21T16:13:13.80-0400 [APP/0]      OUT 16: DEBUG BaseModelMBean - preRegister org.apache.catalina.valves.ErrorReportValve[localhost] Tomcat:type=Valve,host=localhost,name=ErrorReportValve
    2016-06-21T16:13:13.80-0400 [APP/0]      OUT 16: DEBUG LifecycleBase - Setting state for [org.apache.catalina.valves.ErrorReportValve[localhost]] to [INITIALIZED]
    2016-06-21T16:13:13.80-0400 [APP/0]      OUT 16: DEBUG LifecycleBase - Setting state for [org.apache.catalina.valves.ErrorReportValve[localhost]] to [STARTING_PREP]
    2016-06-21T16:13:13.80-0400 [APP/0]      OUT 16: DEBUG LifecycleBase - Setting state for [org.apache.catalina.valves.ErrorReportValve[localhost]] to [STARTING]
    2016-06-21T16:13:13.80-0400 [APP/0]      OUT 16: DEBUG LifecycleBase - Setting state for [org.apache.catalina.valves.ErrorReportValve[localhost]] to [STARTED]
    2016-06-21T16:13:13.80-0400 [APP/0]      OUT 16: DEBUG LifecycleBase - Setting state for [org.apache.catalina.core.StandardHostValve[localhost]] to [INITIALIZING]
    2016-06-21T16:13:13.80-0400 [APP/0]      OUT 16: DEBUG Registry - Managed= Tomcat:type=Valve,host=localhost,name=StandardHostValve
    2016-06-21T16:13:13.80-0400 [APP/0]      OUT 16: DEBUG BaseModelMBean - preRegister org.apache.catalina.core.StandardHostValve[localhost] Tomcat:type=Valve,host=localhost,name=StandardHostValve
    2016-06-21T16:13:13.80-0400 [APP/0]      OUT 16: DEBUG LifecycleBase - Setting state for [org.apache.catalina.core.StandardHostValve[localhost]] to [INITIALIZED]
    2016-06-21T16:13:13.80-0400 [APP/0]      OUT 16: DEBUG LifecycleBase - Setting state for [org.apache.catalina.core.StandardHostValve[localhost]] to [STARTING_PREP]
    2016-06-21T16:13:13.80-0400 [APP/0]      OUT 16: DEBUG LifecycleBase - Setting state for [org.apache.catalina.core.StandardHostValve[localhost]] to [STARTING]
    2016-06-21T16:13:13.80-0400 [APP/0]      OUT 16: DEBUG LifecycleBase - Setting state for [org.apache.catalina.core.StandardHostValve[localhost]] to [STARTED]
    2016-06-21T16:13:13.80-0400 [APP/0]      OUT 16: DEBUG LifecycleBase - Setting state for [Pipeline[StandardEngine[Tomcat].StandardHost[localhost]]] to [STARTING]
    2016-06-21T16:13:13.80-0400 [APP/0]      OUT 16: DEBUG LifecycleBase - Setting state for [Pipeline[StandardEngine[Tomcat].StandardHost[localhost]]] to [STARTED]
    2016-06-21T16:13:13.80-0400 [APP/0]      OUT 16: DEBUG LifecycleBase - Setting state for [StandardEngine[Tomcat].StandardHost[localhost]] to [STARTING]
    2016-06-21T16:13:13.80-0400 [APP/0]      OUT 16: DEBUG LifecycleBase - Setting state for [StandardEngine[Tomcat].StandardHost[localhost]] to [STARTED]
    2016-06-21T16:13:13.80-0400 [APP/0]      OUT 16: DEBUG LifecycleBase - Setting state for [Pipeline[StandardEngine[Tomcat]]] to [INITIALIZING]
    2016-06-21T16:13:13.80-0400 [APP/0]      OUT 16: DEBUG LifecycleBase - Setting state for [Pipeline[StandardEngine[Tomcat]]] to [INITIALIZED]
    2016-06-21T16:13:13.80-0400 [APP/0]      OUT 16: DEBUG LifecycleBase - Setting state for [Pipeline[StandardEngine[Tomcat]]] to [STARTING_PREP]
    2016-06-21T16:13:13.80-0400 [APP/0]      OUT 16: DEBUG LifecycleBase - Setting state for [org.apache.catalina.core.StandardEngineValve[Tomcat]] to [INITIALIZING]
    2016-06-21T16:13:13.80-0400 [APP/0]      OUT 16: DEBUG Registry - Managed= Tomcat:type=Valve,name=StandardEngineValve
    2016-06-21T16:13:13.80-0400 [APP/0]      OUT 16: DEBUG BaseModelMBean - preRegister org.apache.catalina.core.StandardEngineValve[Tomcat] Tomcat:type=Valve,name=StandardEngineValve
    2016-06-21T16:13:13.80-0400 [APP/0]      OUT 16: DEBUG LifecycleBase - Setting state for [org.apache.catalina.core.StandardEngineValve[Tomcat]] to [INITIALIZED]
    2016-06-21T16:13:13.80-0400 [APP/0]      OUT 16: DEBUG LifecycleBase - Setting state for [org.apache.catalina.core.StandardEngineValve[Tomcat]] to [STARTING_PREP]
    2016-06-21T16:13:13.80-0400 [APP/0]      OUT 16: DEBUG LifecycleBase - Setting state for [org.apache.catalina.core.StandardEngineValve[Tomcat]] to [STARTING]
    2016-06-21T16:13:13.80-0400 [APP/0]      OUT 16: DEBUG LifecycleBase - Setting state for [org.apache.catalina.core.StandardEngineValve[Tomcat]] to [STARTED]
    2016-06-21T16:13:13.80-0400 [APP/0]      OUT 16: DEBUG LifecycleBase - Setting state for [Pipeline[StandardEngine[Tomcat]]] to [STARTING]
    2016-06-21T16:13:13.80-0400 [APP/0]      OUT 16: DEBUG LifecycleBase - Setting state for [Pipeline[StandardEngine[Tomcat]]] to [STARTED]
    2016-06-21T16:13:13.80-0400 [APP/0]      OUT 16: DEBUG LifecycleBase - Setting state for [StandardEngine[Tomcat]] to [STARTING]
    2016-06-21T16:13:13.80-0400 [APP/0]      OUT 16: DEBUG LifecycleBase - Setting state for [StandardEngine[Tomcat]] to [STARTED]
    2016-06-21T16:13:13.80-0400 [APP/0]      OUT 16: DEBUG LifecycleBase - Setting state for [org.apache.catalina.mapper.MapperListener@1c7c9651] to [STARTING_PREP]
    2016-06-21T16:13:13.80-0400 [APP/0]      OUT 16: DEBUG LifecycleBase - Setting state for [org.apache.catalina.mapper.MapperListener@1c7c9651] to [STARTING]
    2016-06-21T16:13:13.80-0400 [APP/0]      OUT 16: DEBUG Mapper - Registered host [localhost]
    2016-06-21T16:13:13.80-0400 [APP/0]      OUT 16: DEBUG MapperListener - Register Wrapper [default] in Context [] for service [StandardService[Tomcat]]
    2016-06-21T16:13:13.80-0400 [APP/0]      OUT 16: DEBUG MapperListener - Register Wrapper [dispatcherServlet] in Context [] for service [StandardService[Tomcat]]
    2016-06-21T16:13:13.80-0400 [APP/0]      OUT 16: DEBUG MapperListener - Register Context [] for service [StandardService[Tomcat]]
    2016-06-21T16:13:13.80-0400 [APP/0]      OUT 16: DEBUG MapperListener - Register host [localhost] at domain [null] for service [StandardService[Tomcat]]
    2016-06-21T16:13:13.80-0400 [APP/0]      OUT 16: DEBUG LifecycleBase - Setting state for [org.apache.catalina.mapper.MapperListener@1c7c9651] to [STARTED]
    2016-06-21T16:13:13.80-0400 [APP/0]      OUT 16: DEBUG LifecycleBase - Setting state for [StandardService[Tomcat]] to [STARTED]
    2016-06-21T16:13:13.80-0400 [APP/0]      OUT 16: DEBUG LifecycleBase - Setting state for [StandardServer[-1]] to [STARTED]
    2016-06-21T16:13:13.80-0400 [APP/0]      OUT 16: DEBUG StandardServletEnvironment - Replacing [servletContextInitParams] PropertySource with [servletContextInitParams]
    2016-06-21T16:13:14.18-0400 [HEALTH/0]   OUT healthcheck failed
    2016-06-21T16:13:14.18-0400 [HEALTH/0]   OUT Exit status 1
    2016-06-21T16:13:14.50-0400 [APP/0]      OUT 16: DEBUG LoggingRestTemplate - Created GET request for "https://api.run.pivotal.io/info"
    2016-06-21T16:13:14.50-0400 [APP/0]      OUT 16: DEBUG LoggingRestTemplate - Setting request Accept header to [text/plain, application/json, application/*+json, */*]
    2016-06-21T16:13:14.51-0400 [APP/0]      OUT 16: DEBUG RequestAddCookies - CookieSpec selected: default
    2016-06-21T16:13:14.52-0400 [APP/0]      OUT 16: DEBUG RequestAuthCache - Auth cache not set in the context
    2016-06-21T16:13:14.52-0400 [APP/0]      OUT 16: DEBUG PoolingHttpClientConnectionManager - Connection request: [route: {s}->https://api.run.pivotal.io:443][total kept alive: 0; route allocated: 0 of 5; total allocated: 0 of 10]
    2016-06-21T16:13:14.54-0400 [APP/0]      OUT 16: DEBUG PoolingHttpClientConnectionManager - Connection leased: [id: 0][route: {s}->https://api.run.pivotal.io:443][total kept alive: 0; route allocated: 1 of 5; total allocated: 1 of 10]
    2016-06-21T16:13:14.54-0400 [APP/0]      OUT 16: DEBUG MainClientExec - Opening connection {s}->https://api.run.pivotal.io:443
    2016-06-21T16:13:14.54-0400 [APP/0]      OUT 16: DEBUG DefaultHttpClientConnectionOperator - Connecting to api.run.pivotal.io/52.72.101.87:443
    2016-06-21T16:13:14.54-0400 [APP/0]      OUT 16: DEBUG SSLConnectionSocketFactory - Connecting socket to api.run.pivotal.io/52.72.101.87:443 with timeout 0
    2016-06-21T16:13:14.70-0400 [HEALTH/0]   OUT healthcheck failed
    2016-06-21T16:13:14.70-0400 [HEALTH/0]   OUT Exit status 1
    2016-06-21T16:13:15.74-0400 [HEALTH/0]   OUT healthcheck failed

这是我在 Github 中的user-service 应用程序的链接。

以下是我的 application.yml 文件的内容:

# Spring properties
spring:
  application:
     name: ${vcap.application.name}
  cloud:
    services:
      registrationMethod: route 

---

spring:
  profiles: dev

security:
  basic:
    enabled: false

# Logging
logging:
  level:
    ROOT: INFO
    org.springframework.web: DEBUG

这是我的 ma​​nifest.yml 文件:

instances: 1 
memory: 1024M 
applications: 
   - name: user-service 
     services: 
       - my-eureka-server 
     env: 
       SPRING_PROFILES_ACTIVE: dev 

pom.xml文件如下:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.verizon.microservice</groupId>
    <artifactId>microservice-user-service</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>microservice-user-service</name>
    <description>Demo project Spring Boot</description>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.3.5.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent> 

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <java.version>1.8</java.version>
    </properties>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>Brixton.SR1</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <dependencies>

        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-cloudfoundry-discovery</artifactId>
        </dependency>

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

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

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

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

    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

     <repositories>
        <repository>
            <id>spring-milestones</id>
            <name>Spring Milestones</name>
            <url>https://repo.spring.io/milestone</url>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </repository>
        <repository> 
            <id>spring-release</id> 
            <url>https://repo.spring.io/libs-release</url> 
        </repository>
    </repositories>

</project>

任何人都可以帮助我解决我所缺少的。我试图到处找到解决方案,但找不到。

提前致谢

【问题讨论】:

  • 您是否在 JDK 8 和 Tomcat 8 上运行?
  • 感觉你的应用启动失败了,能不能再看一下你的日志,把日志级别调低可能会更有用一点-logging.level.root = DEBUG
  • 是的,我使用的是 JDK 8 和 Tomcat 8。Tomcat 实例是由 Spring Boot starter pom 自动创建的。
  • 只检查根日志级别到调试
  • 我用 'logging.level.root = DEBUG' 更新了日志。但原因不是很清楚,也可能是我无法理解。

标签: spring spring-boot netflix-eureka cloud-foundry


【解决方案1】:

我现在可以解决问题了。我在 application.yml 文件中缺少 CloudFoundry PORT 环境变量。

这个link 解释了这个问题。

现在,application.yml 文件如下所示:

# HTTP Server
server:
  port: ${vcap.PORT}

# Spring properties
spring:
  application:
     name: ${vcap.application.name}
  cloud:
    services:
      registrationMethod: route 

---

spring:
  profiles: dev
---
security:
  basic:
    enabled: false

---

# Logging
logging:
  level:
    ROOT: INFO
    org.springframework.web: INFO

现在,我的应用程序已在 Cloud Foundry 上启动并运行。我可以使用 URL 访问服务。

【讨论】:

    【解决方案2】:

    与POM配置无关。

    你能在推送这个应用的时候设置域名和主机名吗?以下错误导致健康检查失败是由于:

    Register host [localhost] at domain [null] for service [StandardService[Tomcat]]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-04-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-07-11
      • 2019-03-08
      • 2020-10-30
      • 1970-01-01
      相关资源
      最近更新 更多