在我的Spring MVC应用程序中实现Spring Actuator,而无需添加Spring Boot [英] Implement Spring Actuator in my Spring MVC app without adding Spring boot
问题描述
目前,我有一个使用Spring MVC的旧项目.现在需要实现弹簧启动执行器.所以我的问题是
Currently I have a legacy project that uses spring MVC. Now there is need to implement Spring boot actuator. So my questions are
- 我可以在不添加Spring MVC应用程序的情况下实现Spring Actuator吗? 春季靴子
- 我可以同时使用Spring Boot和Spring MVC吗? 应用.如果是,那么如何.
- Can I implement Spring Actuator in my Spring MVC app without adding Spring boot
- Can I have both Spring boot and spring MVC in one single application. If Yes then how.
如果有人可以逐步描述它的实现,那就太好了. 我正在使用Eclipse,Gradle,Tomcat
It would be great if someone can describe step by step implementation of it. I am using Eclipse, Gradle, Tomcat
推荐答案
回答第一个问题:
-
是的您可以在spring mvc项目中使用执行器.将此添加到pom.xml
yes You can use actuator in your spring mvc project. Add this to pom.xml
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-actuator</artifactId>
<version>Compatible version with mvc</version>
</dependency>
在下面添加配置
Add configuration below
@Configuration
@EnableWebMvc
@Import({EndpointAutoConfiguration.class , PublicMetricsAutoConfiguration.class , HealthIndicatorAutoConfiguration.class
})
public class MyActuatorConfig {
@Bean
@Autowired
public EndpointHandlerMapping endpointHandlerMapping(Collection<? extends MvcEndpoint> endpoints) {
return new EndpointHandlerMapping(endpoints);
}
@Bean
@Autowired
public EndpointMvcAdapter metricsEndPoint(MetricsEndpoint delegate) {
return new EndpointMvcAdapter(delegate);
}
}
2.回答第二个问题
当然您可以使用Spring boot
和spring MVC
,只需简单地在下面将其作为父项来管理所有依赖项版本等.
Of course you can use Spring boot
and spring MVC
, just simple have below as parent to manage all dependencies version etc..
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.6.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
和spring-boot-starter-web
作为依赖项.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
这篇关于在我的Spring MVC应用程序中实现Spring Actuator,而无需添加Spring Boot的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!