11.5 Endpoint监控接口
我们来尝试访问:<http://127.0.0.1:8000/application/beans> ,浏览器显示如下信息:
1. Whitelabel Error Page
3. This application has no explicit mapping for /error, so you are seeing this as a fallback.
5. Mon Jul 17 21:30:35 CST 2017
6. There was an unexpected error (type=Unauthorized, status=401).
7. Full authentication is required to access this resource.
提示没有权限访问。我们去控制台日志可以看到下面这行输出:
1. 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里面添加配置:
1. management.security.enabled=false
重启应用,再次访问,我们可以看到如下输出:
1. [
2. {
3. "context": "application:8000",
4. "parent": null,
5. "beans": [
6. {
7. "bean": "chapter11KotlinSpringbootApplication",
8. "aliases": [
10. ],
11. "scope": "singleton",
12. "type": "com.easy.kotlin.chapter11_kotlin_springboot.Chapter11KotlinSpringbootApplication$$EnhancerBySpringCGLIB$$353fd63e",
13. "resource": "null",
14. "dependencies": [
16. ]
17. },
18. ...
19. {
20. "bean": "org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration",
21. "aliases": [
23. ],
24. "scope": "singleton",
25. "type": "org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration$$EnhancerBySpringCGLIB$$24d31c25",
26. "resource": "null",
27. "dependencies": [
28. "dataSource",
29. "spring.jpa-org.springframework.boot.autoconfigure.orm.jpa.JpaProperties"
30. ]
31. },
32. {
33. "bean": "transactionManager",
34. "aliases": [
36. ],
37. "scope": "singleton",
38. "type": "org.springframework.orm.jpa.JpaTransactionManager",
39. "resource": "class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.class]",
40. "dependencies": [
42. ]
43. },
44. ...
45. {
46. "bean": "spring.devtools-org.springframework.boot.devtools.autoconfigure.DevToolsProperties",
47. "aliases": [
49. ],
50. "scope": "singleton",
51. "type": "org.springframework.boot.devtools.autoconfigure.DevToolsProperties",
52. "resource": "null",
53. "dependencies": [
55. ]
56. },
57. {
58. "bean": "org.springframework.orm.jpa.SharedEntityManagerCreator#0",
59. "aliases": [
61. ],
62. "scope": "singleton",
63. "type": "com.sun.proxy.$Proxy86",
64. "resource": "null",
65. "dependencies": [
66. "entityManagerFactory"
67. ]
68. }
69. ]
70. }
71. ]
可以看出,我们一行代码还没写,只是加了几行配置,SpringBoot已经自动配置初始化了这么多的Bean。我们再访问 <http://127.0.0.1:8000/application/health>
1. {
2. "status": "UP",
3. "diskSpace": {
4. "status": "UP",
5. "total": 120108089344,
6. "free": 1724157952,
7. "threshold": 10485760
8. },
9. "db": {
10. "status": "UP",
11. "database": "MySQL",
12. "hello": 1
13. }
14. }
从上面我们可以看到一些应用的健康状态信息,例如:应用状态、磁盘空间、数据库状态等信息。
