没有 Spring Boot 的 Spring Boot 执行器 [英] Spring Boot Actuator without Spring Boot
问题描述
我一直在研究 Spring/Spring MVC 应用程序,并且希望添加性能指标.我遇到了 Spring Boot Actuator,它看起来是一个很好的解决方案.但是我的应用程序不是 Spring Boot 应用程序.我的应用程序在传统容器 Tomcat 8 中运行.
我添加了以下依赖
//弹簧执行器编译org.springframework.boot:spring-boot-starter-actuator:1.2.3.RELEASE"
我创建了以下配置类.
@EnableConfigurationProperties@配置@EnableAutoConfiguration@Profile(value = {"dev", "test"})@Import(EndpointAutoConfiguration.class)公共类 SpringActuatorConfig {}
我什至按照 StackOverflow 上另一篇文章的建议,在每个配置类上添加了 @EnableConfigurationProperties
.然而这并没有起到任何作用.端点仍未创建并返回 404.
无需弹簧靴即可使用执行器.将此添加到 pom.xml
<依赖><groupId>org.springframework.boot</groupId><artifactId>spring-boot-actuator</artifactId><version>1.3.5.RELEASE</version></依赖><依赖><groupId>org.springframework</groupId><artifactId>spring-web</artifactId><version>4.3.5.RELEASE</version></依赖>
然后在你的配置类中
@Configuration@EnableWebMvc@进口({EndpointAutoConfiguration.class , PublicMetricsAutoConfiguration.class , HealthIndicatorAutoConfiguration.class})公共类 MyActuatorConfig {@豆角,扁豆@自动连线public EndpointHandlerMapping endpointHandlerMapping(Collection extends MvcEndpoint> endpoints) {返回新的 EndpointHandlerMapping(endpoints);}@豆角,扁豆@自动连线公共端点MvcAdapter metricsEndPoint(MetricsEndpoint委托){返回新的 EndpointMvcAdapter(delegate);}}
然后你可以在你的应用程序中看到指标
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
这篇关于没有 Spring Boot 的 Spring Boot 执行器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!