我一直在研究Spring / Spring MVC应用程序,并且希望添加性能指标。我遇到过Spring Boot Actuator,它看起来是一个不错的解决方案。但是我的应用程序不是Spring Boot应用程序。我的应用程序在传统容器Tomcat 8中运行。
我添加了以下依赖
// Spring Actuator compile "org.springframework.boot:spring-boot-starter-actuator:1.2.3.RELEASE"
我创建了以下配置类。
@EnableConfigurationProperties @Configuration @EnableAutoConfiguration @Profile(value = {"dev", "test"}) @Import(EndpointAutoConfiguration.class) public class SpringActuatorConfig { }
我什至可以按照StackOverflow另一篇文章的建议在每个配置类上添加
你可以在没有spring套的情况下使用执行器。将此添加到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>
然后在你的配置类中
@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); } }