Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to customize endpoints for SpringBoot2

Shulou Source: shulou.com Published: 2022-05-31 13:38:21 10月02日 Update

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.

Tags: Endpoints paths attributes knowledge industries projects different practical successful three content practical practical articles methods more cases notes features knowledge points Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Apple Shulou Tech Info vpn Docker MariaDB