Home > Java > javaTutorial > body text

How to customize the endpoint in SpringBoot2

PHPz
Release: 2023-05-12 08:40:15
forward
1408 people have browsed it

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;
	} 
}
Copy after login

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
Copy after login

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
Copy after login
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!

Related labels:
source:yisu.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template