gpt4 book ai didi

java - 如何将spring MVC应用程序注册到spring boot admin

转载 作者:行者123 更新时间:2023-11-30 02:48:17 25 4
gpt4 key购买 nike

我有 Spring MVC Web 应用程序。我通过添加如下依赖项在其中使用了 Spring Boot 执行器。

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-actuator</artifactId>
<version>1.4.0.RELEASE</version>
</dependency>

在我的配置文件中,我导入了如下类。

@Configuration
@ComponentScan({"com.test.*"})
@Import({EndpointWebMvcAutoConfiguration.class,
ManagementServerPropertiesAutoConfiguration.class, EndpointAutoConfiguration.class,
HealthIndicatorAutoConfiguration.class,PublicMetricsAutoConfiguration.class})
@EnableWebMvc
@PropertySource("classpath:appconfig.properties")
public class SpringWebConfig extends WebMvcConfigurerAdapter {
}

现在,当我点击网址“http://localhost:8080/health”时,我收到响应

{"status":"UP","diskSpace":{"status":"UP","total":493767094272,"free":417100754944,"threshold":10485760}}

所以,这很完美。现在我的问题是如何将这个 Spring MVC Web 应用程序注册到 spring-boot-admin 服务器。

谁能帮我吗?

最佳答案

如果您不想使用 Spring Boot 自动配置 (@EnableAutoConfiguration),请查看 spring-boot-admin-starter-client 中的 SpringBootAdminClientAutoConfiguration库中配置了所有用于在管理服务器上注册的组件。

主要是ApplicationRegistrator和一些用于发出频繁注册的taskScheduler。

如果您根本不想使用客户端库,您还可以通过向管理服务器的 /api/applications 端点发送简单的 http post 请求进行注册。

$ curl -H"Content-Type: application/json" --data '{ "serviecUrl":"http://localhost:8080/", "healthUrl":"http://localhost:8080/health", "managementUrl":"http://localhost:8080/","name":"my-app"}' http://<adminserver-host>:<port>/api/applications

关于java - 如何将spring MVC应用程序注册到spring boot admin,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39504010/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com