更新时间:2022-10-14 22:35:17
无需弹簧靴即可使用执行器.将此添加到 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 ***. 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