有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java如何向spring boot admin注册spring MVC应用程序

我有spring MVC web应用程序。我在它里面使用了弹簧启动执行器,添加了如下依赖项

<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 {
}

现在,当我点击url“http://localhost:8080/health”时,我得到了回应

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

所以,这很好用。现在我的问题是如何将这个spring MVC web应用程序注册到spring boot admin server

有人能帮我吗


共 (1) 个答案

  1. # 1 楼答案

    如果您不想使用Spring Boots自动配置(@EnableAutoConfiguration),请查看Spring boot admin starter客户端库中的SpringBootAdminClientAutoConfiguration表单,其中配置了所有用于在管理服务器上注册的组件

    主要是ApplicationRegistrator和一些taskScheduler,用于发布频繁注册

    如果你根本不想使用客户端库,你也可以通过一个简单的http post请求注册到管理服务器的/api/applications端点

    $ 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