11.5 Endpoint监控接口
我们来尝试访问:http://127.0.0.1:8000/application/beans ,浏览器显示如下信息:
Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.
Mon Jul 17 21:30:35 CST 2017
There was an unexpected error (type=Unauthorized, status=401).
Full authentication is required to access this resource.
提示没有权限访问。我们去控制台日志可以看到下面这行输出:
s.b.a.e.m.MvcEndpointSecurityInterceptor : Full authentication is required to access actuator endpoints. Consider adding Spring Security or set 'management.security.enabled' to false.
意思是说,要访问这些Endpoints需要权限,可以通过Spring Security来实现权限控制,或者把权限限制去掉:把management.security.enabled
设置为false
。
我们在application.properties里面添加配置:
management.security.enabled=false
重启应用,再次访问,我们可以看到如下输出:
[
{
"context": "application:8000",
"parent": null,
"beans": [
{
"bean": "chapter11KotlinSpringbootApplication",
"aliases": [
],
"scope": "singleton",
"type": "com.easy.kotlin.chapter11_kotlin_springboot.Chapter11KotlinSpringbootApplication$$EnhancerBySpringCGLIB$$353fd63e",
"resource": "null",
"dependencies": [
]
},
...
{
"bean": "org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration",
"aliases": [
],
"scope": "singleton",
"type": "org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration$$EnhancerBySpringCGLIB$$24d31c25",
"resource": "null",
"dependencies": [
"dataSource",
"spring.jpa-org.springframework.boot.autoconfigure.orm.jpa.JpaProperties"
]
},
{
"bean": "transactionManager",
"aliases": [
],
"scope": "singleton",
"type": "org.springframework.orm.jpa.JpaTransactionManager",
"resource": "class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.class]",
"dependencies": [
]
},
...
{
"bean": "spring.devtools-org.springframework.boot.devtools.autoconfigure.DevToolsProperties",
"aliases": [
],
"scope": "singleton",
"type": "org.springframework.boot.devtools.autoconfigure.DevToolsProperties",
"resource": "null",
"dependencies": [
]
},
{
"bean": "org.springframework.orm.jpa.SharedEntityManagerCreator#0",
"aliases": [
],
"scope": "singleton",
"type": "com.sun.proxy.$Proxy86",
"resource": "null",
"dependencies": [
"entityManagerFactory"
]
}
]
}
]
可以看出,我们一行代码还没写,只是加了几行配置,SpringBoot已经自动配置初始化了这么多的Bean。我们再访问 http://127.0.0.1:8000/application/health
{
"status": "UP",
"diskSpace": {
"status": "UP",
"total": 120108089344,
"free": 1724157952,
"threshold": 10485760
},
"db": {
"status": "UP",
"database": "MySQL",
"hello": 1
}
}
从上面我们可以看到一些应用的健康状态信息,例如:应用状态、磁盘空间、数据库状态等信息。
当前内容版权归 JackChan1999 或其关联方所有,如需对内容或内容相关联开源项目进行关注与资助,请访问 JackChan1999 .