现有webapp上的Spring启动运行状况检查 [英] Spring boot health check on existing webapp
问题描述
我有现有的Spring MVC Web应用程序。现在我只想使用spring-boot-starter-actuator中的健康检查功能。
I have existing Spring MVC web application. Now I just want to use the health check feature present in spring-boot-starter-actuator.
我是春季启动的新手,所以不确定我是否需要将我的完整项目转换为spring boot项目以进行运行状况检查。我可以只包含依赖项并以某种方式仅启用所需的功能吗?
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?
推荐答案
我自己想出来了。而不是 spring-boot-starter-actuator
我包括 spring-boot-actuator
。我不需要使用 @SpringBootApplication
初始化应用程序。相反,现在我只导入所需的auto-config类。所以config类现在看起来像这样
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
依赖于 ManagementServerProperties
因此必须导入它。这对我来说似乎是最基本的配置。让我知道是否有更好的替代方案
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
这篇关于现有webapp上的Spring启动运行状况检查的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!