Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring boot health check on existing webapp

I have existing Spring MVC web application. Now I just want to use the health check feature present in spring-boot-starter-actuator.

I am new to spring boot, so not sure if I need to convert my complete project to spring boot project for health check to work. Can I just include the dependency and somehow enable only the required feature?

like image 340
sidgate Avatar asked Oct 28 '15 06:10

sidgate


1 Answers

I figured it out myself. Instead of spring-boot-starter-actuator I am including spring-boot-actuator. And I don't need to initialize the application using @SpringBootApplication. Instead now I just import the auto-config classes that are required. So the config class now looks like this

@Configuration
@ComponentScan(basePackages = { "org.example" })
@Import({MyApplicationContext.class, EndpointWebMvcAutoConfiguration.class, 
  ManagementServerPropertiesAutoConfiguration.class, EndpointAutoConfiguration.class, 
  HealthIndicatorAutoConfiguration.class})
@PropertySource("classpath:app.properties")
@EnableWebMvc
public class MyWebApplicationContext {
...
}

EndpointWebMvcAutoConfiguration depends on ManagementServerProperties hence had to import it. This seems to be the bare minimum configuration for me. Let me know if there is any better alternative

like image 169
sidgate Avatar answered Sep 19 '22 15:09

sidgate