弹簧启动器没有弹簧启动器 [英] Spring Boot Actuator without Spring Boot

查看:144
本文介绍了弹簧启动器没有弹簧启动器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直致力于Spring / Spring MVC应用程序,我正在寻找性能指标。我遇到过Spring Boot Actuator,它看起来像是一个很好的解决方案。但是我的应用程序不是Spring Boot应用程序。我的应用程序在传统容器Tomcat 8中运行。



我添加了以下依赖项

  // Spring Actuator 
编译org.springframework.boot:spring-boot-starter-actuator:1.2.3.RELEASE

我创建了以下配置类。

  @EnableConfigurationProperties 
@Configuration
@EnableAutoConfiguration
@Profile(value = {dev,test})
@Import(EndpointAutoConfiguration.class)
public class SpringActuatorConfig {

}

我甚至按照建议在每个配置类上添加@EnableConfigurationProperties在StackOverflow上的另一篇文章。然而,这没有做任何事情。端点仍未创建并返回404s。

解决方案

您可以在没有弹簧启动的情况下使用执行器。
将此添加到pom.xml

 < dependency> 
< groupId> org.springframework.boot< / groupId>
< artifactId> spring-boot-actuator< / artifactId>
< version> 1.3.5.RELEASE< / version>
< / dependency>

<依赖>
< groupId> org.springframework< / groupId>
< artifactId> spring-web< / artifactId>
< version> 4.3.5.RELEASE< / version>
< / dependency>

然后在你的配置类中

  @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委托){
返回新的EndpointMvcAdapter(委托);
}
}

然后你可以看到应用程序中的指标




I've been working on a Spring/Spring MVC application and I'm looking to add performance metrics. I've come across Spring Boot Actuator and it looks like a great solution. However my application is not a Spring Boot application. My application is running in a traditional container Tomcat 8.

I added the following dependencies

// Spring Actuator
compile "org.springframework.boot:spring-boot-starter-actuator:1.2.3.RELEASE"

I created the following config class.

@EnableConfigurationProperties
@Configuration
@EnableAutoConfiguration
@Profile(value = {"dev", "test"})
@Import(EndpointAutoConfiguration.class)
public class SpringActuatorConfig {

}

I even went as far as adding @EnableConfigurationProperties on every configuration class as suggested on another post on StackOverflow. However that didn't do anything. The endpoints are still not being created and return 404s.

解决方案

You can use actuator without spring boot. Add this to pom.xml

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-actuator</artifactId>
    <version>1.3.5.RELEASE</version>
</dependency>

<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-web</artifactId>
    <version>4.3.5.RELEASE</version>
</dependency>

And then in your config class

@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);
    }
}

And then you can see the metrics in your application

http://localhost:8085/metrics

这篇关于弹簧启动器没有弹簧启动器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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