Spring Noob: OK. I start with a STS Spring Starter Project / Maven / Java 8 / Spring Boot 2.0, and select the Web and Actuator dependencies. It builds and runs fine, and reponds to http://localhost:8080/actuator/health. I add an "Endpoint" to the main application class, so that it looks like this.
package com.thumbsup;
import org.springframework.boot.SpringApplication;
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.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class YourStash11Application {
public static void main(String[] args) {
SpringApplication.run(YourStash11Application.class, args);
}
@Endpoint(id="mypoint")
public class CustomPoint {
@ReadOperation
public String getHello(){
return "Hello" ;
}
}
}
I try to enable everything in application.properties:
management.endpoints.enabled-by-default=true
management.endpoint.conditions.enabled=true
management.endpoint.mypoint.enabled=true
management.endpoints.web.exposure.include=*
But when it builds, there's no reference to mapping /actuator/mypoint, and
http://localhost:8080/actuator/mypoint and
http://localhost:8080/application/mypoint
both return 404 errors.
What am I missing? Thanks!
Spring Actuator Custom Endpoints We can create our own custom actuator endpoints using @Endpoint annotation on a class. Then we have to use @ReadOperation , @WriteOperation , or @DeleteOperation annotations on the methods to expose them as actuator endpoint bean.
In a Spring Boot application, we expose a REST API endpoint by using the @RequestMapping annotation in the controller class. For getting these endpoints, there are three options: an event listener, Spring Boot Actuator, or the Swagger library.
Here are some of the most common Spring Boot Actuator endpoints: /health: It shows application health information. /info: It displays arbitrary application info. /metrics: It gives all metrics related information for the current application.
OK, solved:
@Endpoint(id="mypoint")
@Component
public class myPointEndPoint {
@ReadOperation
public String mypoint(){
return "Hello" ;
}
}
What was missing was the "@Component" annotation. But, where is this in the docs?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With