当前位置: 首页 > 知识库问答 >
问题:

spring boot 2.0.0的样板项目不公开自定义执行器endpoint

高宇定
2023-03-14
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.stereotype.Component;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Component
@Endpoint(id="testing-user")
public class ActiveUsersEndpoint {

private final Map<String, User> users = new HashMap<>();

ActiveUsersEndpoint() {
    this.users.put("A", new User("Abcd"));
    this.users.put("E", new User("Fghi"));
    this.users.put("J", new User("Klmn"));
}

@ReadOperation
public List getAll() {
    return new ArrayList(this.users.values());
}

@ReadOperation
public User getActiveUser(@Selector String user) {
    return this.users.get(user);
}

public static class User {
    private String name;

    User(String name) {
        this.name = name;
    }

    public String getName() {
        return this.name;
    }

    public void setName(String name) {
        this.name = name;
    }
}
}

在我的application.yml中,我添加了:

management:
    endpoints:
        web:
            base-path: /
            exposure:
                include: '*'

没有太多的资源可用,那些是,没有帮助。

共有1个答案

漆雕彬彬
2023-03-14

找到答案了。

不使用@component创建bean,而是使用一个配置文件来创建endpoint的所有bean。例如,配置文件可能如下所示:

@ManagementContextConfiguration
public class HealthConfiguration {

@Bean
public ActiveUsersEndpoint activeUsersEndpoint() {
    return new ActiveUsersEndpoint();
}
// Other end points if needed...
}

重要的是在参考资料中有spring.factors文件。该文件将指向您创建所有endpointbean的配置文件:org.springframework.boot.actuate.autocigure.web.managementcontextconfiguration=com.foo.bar.healthconfiguration

 类似资料:
  • 自定义脚本 Gradle构建脚本的标准名称是build.gradle,在一个多项目构建的环境中,你想自定义你的构建脚本名称来显得高大上一点,因为多个项目有相同的构建脚本名称可能会混淆,接下来介绍如何使用自定义的脚本名称。 还是之前那个例子,假设所有的子项目路径都是以todo-开头,比如web子项目就是在todo-web目录下,构建脚本名称应该清晰的表示它的作用,如下图所示: 要使这个结构起作用关键

  • 本文向大家介绍destoon调用自定义模板及样式的公告栏,包括了destoon调用自定义模板及样式的公告栏的使用技巧和注意事项,需要的朋友参考一下 destoon中默认的首页公告栏调用方法如下: 这个标签引用的模板文件是template/default/tag/list.htm文件。 当我们不想用这个list.htm文件,而想要用到自己写的样式和模板,就可以复制一份这个文件,把文件名改为例如 li

  • 我们快要完成这个应用了,做完一点点自定义样式之后,就算正式完成了。在定义我们的样式之前我们将要给模板文件添加一些类。 > 修改src/pages/home/home.ts 为如下: <ion-header> <ion-navbar color="secondary"> <ion-title> <ion-searchbar color="primary" pl

  • 我正在尝试为Spring启动应用程序编写自定义终结点。我编写了自定义终结点实现,如下所示。我没有包括额外的内容,如导入以减少代码的大小。 编写完以上代码后,我重新启动了应用程序并尝试从/test访问endpoint。但是,endpoint不可用。以下是Spring Boot start应用程序。 除此之外,我有一切运行Spring Boot致动器。我可以访问默认endpoint,如/info、/m

  • 我已经激活了Spring执行器普罗米修斯endpont<代码>/执行器/普罗米修斯。通过增加对千分尺和执行器的依赖,并启用prometheus Endpont。我如何获得自定义度量?

  • 我目前正在尝试将我们的prometheus lib迁移到spring Boot2.0.3版本。我们使用普罗米修斯的自定义路径,到目前为止,我们使用一个工作来确保这一点。由于信息endpoint和健康endpoint可能有自定义路径,因此使用。我尝试指定,但它仍然只能在下访问。 如何使用自定义路径或普罗米修斯? 我们使用以下库启用prometheus(我们的build.gradle的片段) 我们还使