How to customize endpoints for SpringBoot2
This article mainly introduces the relevant knowledge of "how to customize the endpoint of SpringBoot2". The editor shows you the operation process through an actual case. The method of operation is simple and fast, and it is practical. I hope this article of "how to customize the endpoint of SpringBoot2" can help you solve the problem.
SpringBoot2 new feature custom endpoint package com.yan.otlan.springboot; import org.springframework.boot.actuate.endpoint.annotation.Endpoint;import org.springframework.boot.actuate.endpoint.annotation.ReadOperation;import org.springframework.boot.actuate.endpoint.annotation.Selector;import org.springframework.stereotype.Component; @ Endpoint (id = "customPoint") @ Componentpublic class StatusEndPoint {@ ReadOperation public String getCustom (@ Selector String name) {return "MyName is." + name }}
Only three annotations are needed: @ endpoint, @ ReadOperation, @ Selector
Start the springboot project
Seeing the red mapped shows that it can be successful.
Visit http://127.0.0.1:8080/actuator/customPoint/156
Result
SpringBoot-Actuator- Custom Endpoint Properties close all endpoints management.endpoints.enabled-by-default: false modify access project path
The default access path is / actuator, which can be modified by modifying the following properties
Management.endpoints.web.base-path: / actuator
For example, the default access path is http://ip:port/actuator
If you want to change access path to http://ip:port/myActuator
You can set the property to / myActuator
The path must start with /, otherwise it cannot be accessed
That's all for "how to customize endpoints for SpringBoot2". Thank you for reading. If you want to know more about the industry, you can follow the industry information channel. The editor will update different knowledge points for you every day.