在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";
}
}
答案 0 :(得分:2)
您可以在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);
}
}
引用:cron