Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
396 views
in Technique[技术] by (71.8m points)

java - 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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...