[英]How migrate an actuator that extends AbstractMvcEndpoint to Spring Boot 2.x?
在Spring Boot 1.5.x中,我通過擴展AbstractMvcEndpoint
創建了一個執行器端點。 但是此類在Spring Boot 2.x中不再存在。
我將如何升級以下課程?
@Configuration
@ManagementContextConfiguration
public class MyManagementController extends AbstractMvcEndpoint
{
private static final Logger logger = LoggerFactory.getLogger( MyManagementController.class );
public MyManagementController()
{
super( "/mypath, false, true );
}
@PostConstruct
public void completeSetup()
{
setEnabled( true );
}
@GetMapping(
value = "/" + PATH_PIECE_MANAGERS,
produces = MediaType.APPLICATION_JSON_VALUE
)
@ResponseBody
public String test(HttpServletRequest request) throws Exception
{
return "ok";
}
}
您可以在spring-boot 2.x中使用注釋@RestControllerEndpoint
,在這里您可以將自己的請求映射與HttpMethods一起使用。 這是一個示例:
@Component
@RestControllerEndpoint(id = "remote")
public class CustomActuator {
@RequestMapping(value = {"/{actuatorInput}"}, produces = MediaType.APPLICATION_JSON_VALUE, method = RequestMethod.GET)
@ResponseBody
public Map<String, Object> feature(@PathVariable("actuatorInput") String actuatorInput) {
System.out.println("actuatorInput : " + actuatorInput);
Map<String, Object> details = new HashMap<>();
details.put("input", actuatorInput);
return details;
}
}
或者,您可以使用@Endpoint(id = "endpoint")
來使用@ReadOperation
和@WriteOperation
進行GET和POST操作。
這是一個示例:
@Component
@Endpoint(id = "custom-health")
public class CustomHealthEndpoint {
@ReadOperation
public String customEndPointByName(@Selector String name) {
return "custom-end-point : " + name;
}
@WriteOperation
public void writeOperation(@Selector String name) {
System.out.println("Write Operation! :: " + name);
}
@DeleteOperation
public void deleteOperation(@Selector String name){
System.out.println("Delete Operation! :: " + name);
}
}
參考: https : //www.javadevjournal.com/spring-boot/spring-boot-actuator-custom-endpoint/
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.