一、 spring骨架生成 -- spring initializr
可以生成Maven、Gradle,可以自由选择依赖,自由输入或者通过 “switch to the full version”选择,选择完成后,单击“generate Project ” 生成spring boot框架。在本次学习中采用了 maven project进行框架生成。
二、pom.xml 解读
1、自动生成的框架通过 将 spring-boot-starter-parent 作为parent自动引入了 spring-boot-dependencies,并进行了自动配置srping-boot-maven-plugin。
2、非自动生成的框架可以自行配置panrent。
<dependencyManagement> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-dependencies</artifactId> <version>2.1.1.RELEASE</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement>
三 actuator 健康检查、审计、统计、监控。只有health、info通过http暴露了出来。
Endpoint ID | Description |
---|---|
auditevents | 显示应用暴露的审计事件 (比如认证进入、订单失败) |
info | 显示应用的基本信息 |
health | 显示应用的健康状态 |
metrics | 显示应用多样的度量信息 |
loggers | 显示和修改配置的loggers |
logfile | 返回log file中的内容(如果logging.file或者logging.path被设置) |
httptrace | 显示HTTP足迹,最近100个HTTP request/repsponse |
env | 显示当前的环境特性 |
flyway | 显示数据库迁移路径的详细信息 |
liquidbase | 显示Liquibase 数据库迁移的纤细信息 |
shutdown | 让你逐步关闭应用 |
mappings | 显示所有的@RequestMapping路径 |
scheduledtasks | 显示应用中的调度任务 |
threaddump | 执行一个线程dump |
heapdump | 返回一个GZip压缩的JVM堆dump |
2、打开/关闭 actuator 方法
在application.properties 中配置 management.endpoint.shutdowm.enabled = true
3、暴露 actuator
默认,actuator endpoint通过JMX被暴露,而通过HTTP暴露的只有health
和info
。
以下是你可以通过应用的properties可以通过HTTP和JMX暴露的actuator endpoint。
-
通过HTTP暴露Actuator endpoints。
# Use "*" to expose all endpoints, or a comma-separated list to expose selected ones management.endpoints.web.exposure.include=health,info management.endpoints.web.exposure.exclude=
-
通过JMX暴露Actuator endpoints。
# Use "*" to expose all endpoints, or a comma-separated list to expose selected ones management.endpoints.jmx.exposure.include=* management.endpoints.jmx.exposure.exclude=