小编Har*_*hil的帖子

应用程序状态关闭,当 mongo 使用弹簧引导执行器关闭时

我已经为带有数据库测试的 Spring Boot 执行器创建了示例项目。当我点击 URL 时运行应用程序后

  • 当 Mongo DB 运行时
  • 网址:http://localhost:8080/health
  • 响应:`{"status":"UP","diskSpace":{"status":"UP","total":493767094272,"free":404928278528,"threshold":10485760},"mongo":{" status":"UP","version":"3.0.2"}}

`

  • 当 Mongo DB 未运行时
  • 网址: http://localhost:8080/health
  • 回复:

    在等待与 ReadPreferenceServerSelector{readPreference=primary} 匹配的服务器时,30000 毫秒后超时。集群状态的客户端视图为{type=UNKNOWN, servers=[{address=localhost:27017, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketOpenException: Exception opening socket},由{java.net. ConnectException:连接被拒绝:connect}}]"}}

问题:当我的 mongodb 未运行时,为什么应用程序状态为“DOWN”。我希望我的应用程序状态“UP”天气 mongodb 是“DOWN”或“UP”。

下面是我的 Spring Boot 应用程序的主类。

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);
    }
}
Run Code Online (Sandbox Code Playgroud)

pom.xml

<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 …
Run Code Online (Sandbox Code Playgroud)

java mongodb maven spring-boot spring-boot-actuator

5
推荐指数
1
解决办法
4891
查看次数

来自自定义表的 Spring Security 身份验证

我正在研究 Spring Security,它有很好的功能,但我的要求有点不同。我有一张表: 1. Employee(字段 ename、epassword)

我想从这个表中验证用户身份,但使用 spring security。我知道 Spring Security 有某种启用和角色功能,但无法了解如何从我的表中获取身份验证。我看过一些例子并谷歌搜索某些链接,但一些好的链接会更有帮助。

java security spring spring-security

4
推荐指数
1
解决办法
1856
查看次数

Spring启动执行器MySQL数据库健康检查

我用MySQL数据库设计了一个演示Spring启动应用程序CRUD操作.我的application.properties文件如下.

spring.boot.admin.url=http://localhost:8081
spring.datasource.url= jdbc:mysql://localhost:3306/springbootdb
spring.datasource.username=root
spring.datasource.password=admin
endpoints.health.sensitive=false
management.health.db.enabled=true
management.health.defaults.enabled=true
management.health.diskspace.enabled=true
spring.jpa.hibernate.ddl-auto=create-drop
Run Code Online (Sandbox Code Playgroud)

弹簧执行器的POM.xml如下.

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
    <groupId>de.codecentric</groupId>
    <artifactId>spring-boot-admin-starter-client</artifactId>
    <version>1.3.4</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)

当我尝试点击网址" http:// localhost:8080/health "时,我收到{"status":"UP"}作为回复.我想用弹簧启动执行器监视我的数据库(MySQL).我想查看我的数据库状态.

有人可以帮忙吗?

java mysql spring spring-boot spring-boot-actuator

2
推荐指数
2
解决办法
7847
查看次数