在我的Spring MVC应用程序中实现Spring Actuator,而无需添加Spring Boot [英] Implement Spring Actuator in my Spring MVC app without adding Spring boot

查看:482
本文介绍了在我的Spring MVC应用程序中实现Spring Actuator,而无需添加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

  1. 我可以在不添加Spring MVC应用程序的情况下实现Spring Actuator吗? 春季靴子
  2. 我可以同时使用Spring Boot和Spring MVC吗? 应用.如果是,那么如何.
  1. Can I implement Spring Actuator in my Spring MVC app without adding Spring boot
  2. 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

推荐答案

回答第一个问题:

  1. 是的您可以在spring mvc项目中使用执行器.将此添加到pom.xml

  1. 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 bootspring 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屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆