Açıklaması şöyle
It may be the case that you want to change the functionality of an inbuild endpoint such as changing its output. Spring boot actuator allows you to modify its inbuilt endpoints by extending them.Örnek
Following are the steps involved:
- Create a class with @EndpointWebExtension annotation. You can also annotate it with @EndpointExtension.
- @EndpointWebExtension is a specialization of @EndpointExtension for web applications.
- For JMX, use @EndpointJmxExtension or @EndpointExtension annotation.
- This annotation should have an endpoint property. Its value should be the class name of the endpoint that you want to extend.
- For this example, we will be extending info endpoint, so its value will be InfoEndpoint.class.
- As with creating a custom endpoint, provide methods annotated with @ReadOperation, @DeleteOperation or @WriteOperation.
Şöyle yaparız
@Component @EndpointWebExtension(endpoint=InfoEndpoint.class) public class EnvEndpointCustomizer { @ReadOperation public Environment getEnvironmentInfo() { return new Environment(); } // model class for info output class Environment { String ram; String hdd; public String getRam() { return ram; } public void setRam(String ram) { this.ram = ram; } public String getHdd() { return hdd; } public void setHdd(String hdd) { this.hdd = hdd; } // constructor public Environment() { this.ram = "8GB"; this.hdd = "500GB"; } } }
http://localhost:8080/actuator/info adresine gidersek çıktısı şöyle olur
{"ram":"8GB","hdd":"500GB"}
Hiç yorum yok:
Yorum Gönder