首页 > 解决方案 > SpringBoot2中的自定义导航执行器端点

问题描述

我编写了 Spring-Boot 版本 2,自定义端点执行器代码,并尝试使用 @Selector 选项使其可导航,

1) 当我在浏览器中输入 URL http://localhost/actuator/notes/1.0时,它给了我 400 作为错误代码,预期的输出应该是 ** Version 1.0 **

2) 当我在浏览器中输入 URL http://localhost/actuator/notes时,它给了我预期的输出,即 ** 1.1 版 ** ** 1.0 版 **

@Component
@Endpoint(id="notes")
public class NotesEndPoint {
     String notesOne=" ** Version 1.0 ** ";
     String notesTwo = "** Version 1.1 **";

     @ReadOperation
     public String selectNotes(@Selector String selector ) {
     if("1.0".equals(selector)) return notesOne ;
     else if("1.1".equals(selector)) return notesTwo ;
     else return getNotesVersion();
    }

    @ReadOperation
    public String getNotesVersion(){
    return notesTwo + notesOne;
    }

}

标签: spring-boot-actuatorspring-boot-2

解决方案


推荐阅读