首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >应用状态下降,当芒果与弹簧启动执行器关闭时

应用状态下降,当芒果与弹簧启动执行器关闭时
EN

Stack Overflow用户
提问于 2017-01-23 09:46:20
回答 2查看 6.7K关注 0票数 5

我已经创建了使用数据库测试的弹簧引导执行器示例项目。在运行应用程序之后,当我点击URL

  • 当Mongo DB运行时
  • 网址:http://localhost:8080/health
  • 响应:{“状态”:“向上”,“diskSpace”:{“状态”:“向上”,“总计”:493767094272,“自由”:404928278528,“阈值”:10485760},“状态”:{“向上”,“版本”:“3.0.2”}}

`

  • 当Mongo DB没有运行时
  • 网址:http://localhost:8080/health
  • 响应: {“状态”:“向下”,“状态”:{“状态”:“向上”,“总计”:493767094272,“自由”:404929720320,“阈值”:10485760},“mongo”:{“状态”:“下降”,"error":"org.springframework.dao.DataAccessResourceFailureException:在等待与ReadPreferenceServerSelector{readPreference=primary}.匹配的服务器时,在30000 ms之后超时。群集状态的客户端视图是{type=UNKNOWN、servers={address=localhost:27017、type=UNKNOWN、state=CONNECTING、servers=异常打开套接字},这是由{java.net.ConnectException: Connection :connect}}引起的;嵌套异常是com.mongodb.MongoTimeoutException:在等待与ReadPreferenceServerSelector{readPreference=primary}.匹配的服务器时,在30000 ms之后超时。群集状态的客户端视图是{type=UNKNOWN、servers={address=localhost:27017、type=UNKNOWN、state=CONNECTING、servers=异常打开套接字},由{java.net.ConnectException: Connection拒绝:connect}“}}引起。

问题:为什么当我的mongodb没有运行时应用程序状态“下降”。我希望我的应用程序状态“向上”,mongodb是“下降”或“向上”。

下面是我的spring引导应用程序的主要类。

代码语言:javascript
运行
复制
package com.company.testing;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class Application {

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

pom.xml

代码语言:javascript
运行
复制
<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>
    <artifactId>SpringBootSample</artifactId>
    <version>0.0.1</version>
    <name>Spring Boot Sample</name>
    <description>Spring Boot Sample for spring boot actuator</description>
    <groupId>com.company.testing</groupId>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.4.3.RELEASE</version>
    </parent>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</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-data-mongodb</artifactId>
        </dependency>


    </dependencies>

    <properties>
        <java.version>1.8</java.version>
    </properties>

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

Stack Overflow用户

发布于 2017-01-23 13:36:16

Spring使用HealthIndicatorAutoconfiguration配置各种与健康相关的bean。其中一个bean名为healthAggregator,它使用实现或OrderedHealthAggregator。它将使用所有健康指标中的最低状态来提供总体应用程序状态(这就是为什么您开始使用整个应用程序的原因)。

您可以关闭MongoDb监视(management.health.mongo.enabled=false),也可以编写您自己的AbstractHealthAggregator实现,它将忽略MongoDb关闭,并在您的配置中提供:

代码语言:javascript
运行
复制
    @Bean
    public MyHealthAggregator healthAggregator() {
        return new MyHealthAggregator();
    }
票数 3
EN
查看全部 2 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/41803253

复制
相关文章

相似问题

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