Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
370 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 Reply

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...