diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/MetricFilterAutoConfiguration.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/MetricFilterAutoConfiguration.java index 20d0453e1c..f9f451dfd3 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/MetricFilterAutoConfiguration.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/MetricFilterAutoConfiguration.java @@ -45,7 +45,7 @@ import org.springframework.web.servlet.HandlerMapping; @ConditionalOnClass({ Servlet.class, ServletRegistration.class, OncePerRequestFilter.class, HandlerMapping.class }) @AutoConfigureAfter(MetricRepositoryAutoConfiguration.class) -@ConditionalOnProperty(name = "endpoints.metrics.filter.enabled", matchIfMissing = true) +@ConditionalOnProperty(name = "endpoints.metrics.enabled", matchIfMissing = true) public class MetricFilterAutoConfiguration { @Autowired diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/MetricFilterAutoConfigurationTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/MetricFilterAutoConfigurationTests.java index b513011808..7ff1b01c68 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/MetricFilterAutoConfigurationTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/MetricFilterAutoConfigurationTests.java @@ -31,6 +31,7 @@ import org.mockito.stubbing.Answer; import org.springframework.boot.actuate.metrics.CounterService; import org.springframework.boot.actuate.metrics.GaugeService; +import org.springframework.boot.test.EnvironmentTestUtils; import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -77,6 +78,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers. * * @author Phillip Webb * @author Andy Wilkinson + * @@author Stephane Nicoll */ public class MetricFilterAutoConfigurationTests { @@ -175,6 +177,16 @@ public class MetricFilterAutoConfigurationTests { context.close(); } + @Test + public void skipsFilterIfPropertyDisabled() throws Exception { + AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(); + EnvironmentTestUtils.addEnvironment(context, "endpoints.metrics.enabled:false"); + context.register(Config.class, MetricFilterAutoConfiguration.class); + context.refresh(); + assertThat(context.getBeansOfType(Filter.class).size(), equalTo(0)); + context.close(); + } + @Test public void controllerMethodThatThrowsUnhandledException() throws Exception { AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(