Home  >  Article  >  Java  >  How to customize the endpoint in SpringBoot2

How to customize the endpoint in SpringBoot2

PHPz
PHPzforward
2023-05-12 08:40:151409browse

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")
@Component
public class StatusEndPoint { 
	@ReadOperation
	public String getCustom(@Selector String name) {
		return "MyName is ." + name;
	} 
}

Only requires three annotations @endpoint, @ReadOperation, @Selector

Start the springboot project

How to customize the endpoint in SpringBoot2

Seeing the red mapped indicates success

Visit http://127.0.0.1:8080/actuator/customPoint /156

Result

How to customize the endpoint in SpringBoot2

##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 the access path to

http://ip:port/myActuator

, you can set the property to

/myActuator

The path must start with /, otherwise it cannot be accessed

The above is the detailed content of How to customize the endpoint in SpringBoot2. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:yisu.com. If there is any infringement, please contact admin@php.cn delete