SpringBoot生产级特性简单总结

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/HcJsJqJSSM/article/details/83096230

一:环境准备.

   1. Chrome浏览器,JSONView插件,SpringBoot框架,Maven.

    JSONView插件的安装:安装教程.(用于美化Json输出的).

   SpringBoot框架的版本:1.5.10.RELEASE.

    安装完截图如下

2. Maven依赖添加.

		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-actuator</artifactId>
		</dependency>

 3. application.properties中添加如下:(开启性能指标)这个其实是actuator插件默认包含的,并且开启的.

endpoints.metrics.enabled=true

4. 启动SpringBoot程序,然后浏览器访问如下.(我修改的端口是8082)

发现访问异常了.阅读错误提示信息发现是,访问授权的问题.在application.properties中将管理授权关闭了,默认是开启的.

management.security.enabled=false

5. 然后重新启动程序.

上面包含了大量性能指标信息,包括内存,CPU,Java堆,线程,Java类,JVM垃圾回收,HTTP会话.

     5.1 关闭metrics端点.

endpoints.metrics.enabled=false

   5.2 关闭所有端点,仅开启metrics端点.

endpoints.enabled=false
endpoints.metrics.enabled=true

  5.3 修改metrics端点的名称.

  

endpoints.metrics.id=testmetrics

5.4:修改metrics端点的请求路径.

endpoints.metrics.path=/endpoints/metrics

6. SpringBoot的Actuator插件提供了如下端点信息.

autoconfig          获取自动配置的信息.

beans     获取Spring Bean基本信息.

configprops :       获取配置项信息.

dump:         获取当前线程基本信息.

env:       获取当前的环境变量信息.

health:              获取检查检查信息.

info:                获取应用基本信息.

mappings:获取请求映射基本信息.

trace:                 获取请求调用信息.

7. 查看SpringBoot给我们提供了哪些端点?

 使用HATEOAS插件.它可以汇总端点信息,包括各个端点的名称与链接.

 使用HATEOAS插件,Maven添加依赖.

		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-hateoas</artifactId>
		</dependency>

 这个时候我们就拥有了actuator端点了.

 

 禁用actuator端点.

endpoints.actuator.enabled=false

8. 使用HAL bROWSER图形化工具,更好地查看端点信息.

		<dependency>
			<groupId>org.webjars</groupId>
			<artifactId>hal-browser</artifactId>
		</dependency>

 这个时候浏览器访问站点.(非常漂亮的图形界面)

 

9. 进一步了解Actuator,开启Actuator插件.

		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-actuator-docs</artifactId>
		</dependency>

如果有些端点不能访问可能是框架为了安全就不暴露这么多的端点了.

例如:Spring Boot 2.0 的Actuator只暴露了health和info端点,其它的一堆怎么也打不开.

在:management.endpoints.web.exposure.include= 指定要暴露的端点就可以的.

猜你喜欢

转载自blog.csdn.net/HcJsJqJSSM/article/details/83096230