2016-09-22 230 views
0

我设计了一个带有MySQL数据库的演示程序spring boot应用程序CRUD操作。我的application.properties文件如下。Spring引导执行程序MySQL数据库健康检查

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 

弹簧执行器的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> 

当我尝试打网址 “http://localhost:8080/health”,我得到{ “地位”: “UP”}如响应。我想用弹簧启动执行器监视我的数据库(MySQL)。我想看到我的数据库状态。

任何人都可以请帮忙吗?

+0

你需要数据库的状态吗?是否可以请您解释更多 –

+0

是的,我需要数据库状态,而且我并不十分清楚弹簧启动时我们可以使用弹簧启动器执行的最大数据库细节。 – Harshil

回答

5

我会检查the documentation - 以匿名形式暴露全部细节需要禁用执行器的安全性。

如果这不是您想要的,您可以完全控制安全性并使用Spring Security编写自己的规则。

+0

哇。明白了..谢谢你。 – Harshil

1

如果您使用弹簧安全功能,则执行器默认启用安全功能。

添加这在你的属性文件 -

management.security.enabled= false 

OR

添加用户名和密码在属性文件 -

security.user.name= username 
security.user.password = password 

,并使用这些凭据访问驱动器的端点。