首页 文章

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

提问于
浏览
1

我有 Spring 季MVC网络应用程序 . 我通过添加如下的依赖性在其中使用了 spring 启动器 .

<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服务器 .

谁能帮我 ?

1 回答

  • 2

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

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

    如果你没有't want to use the client-lib at all you could also register via a simple http post request to the admin-server' s /api/applications endpoints .

    $ 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
    

相关问题