Spring Noob:好的。我先从STS Spring Starter项目/ Maven / Java 8 / Spring Boot 2.0开始,然后选择Web和Actuator依赖项。它可以正常构建和运行,并响应http://localhost:8080/actuator/health。我在主应用程序类中添加了一个“端点”,因此它看起来像这样。
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" ;
}
}
}
我尝试启用application.properties中的所有内容:
management.endpoints.enabled-by-default=true
management.endpoint.conditions.enabled=true
management.endpoint.mypoint.enabled=true
management.endpoints.web.exposure.include=*
但是在构建时,没有引用映射/ actuator / mypoint,并且
http://localhost:8080/actuator/mypoint和
http://localhost:8080/application/mypoint
都返回404错误。
我想念什么?谢谢!
最佳答案
好的,解决了:
@Endpoint(id="mypoint")
@Component
public class myPointEndPoint {
@ReadOperation
public String mypoint(){
return "Hello" ;
}
}
缺少的是“@Component”注释。但是,这在文档中哪里呢?