parent
fccab42711
commit
d3e2e22f8c
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2012-2016 the original author or authors.
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -28,6 +28,7 @@ import org.springframework.boot.autoconfigure.AutoConfigureAfter;
|
|||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.boot.autoconfigure.web.ErrorAttributes;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
|
|
@ -42,6 +43,7 @@ import org.springframework.web.servlet.DispatcherServlet;
|
|||
*/
|
||||
@ConditionalOnClass({ Servlet.class, DispatcherServlet.class, ServletRegistration.class })
|
||||
@AutoConfigureAfter(TraceRepositoryAutoConfiguration.class)
|
||||
@ConditionalOnProperty(name = "endpoints.trace.filter.enabled", matchIfMissing = true)
|
||||
@EnableConfigurationProperties(TraceProperties.class)
|
||||
@Configuration
|
||||
public class TraceWebFilterAutoConfiguration {
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ import org.springframework.boot.actuate.trace.TraceProperties;
|
|||
import org.springframework.boot.actuate.trace.TraceRepository;
|
||||
import org.springframework.boot.actuate.trace.WebRequestTraceFilter;
|
||||
import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration;
|
||||
import org.springframework.boot.test.util.EnvironmentTestUtils;
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
|
@ -58,6 +59,19 @@ public class TraceWebFilterAutoConfigurationTests {
|
|||
context.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void skipsFilterIfPropertyDisabled() throws Exception {
|
||||
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
|
||||
EnvironmentTestUtils.addEnvironment(context,
|
||||
"endpoints.trace.filter.enabled:false");
|
||||
context.register(PropertyPlaceholderAutoConfiguration.class,
|
||||
TraceRepositoryAutoConfiguration.class,
|
||||
TraceWebFilterAutoConfiguration.class);
|
||||
context.refresh();
|
||||
assertThat(context.getBeansOfType(WebRequestTraceFilter.class).size()).isEqualTo(0);
|
||||
context.close();
|
||||
}
|
||||
|
||||
@Configuration
|
||||
static class CustomTraceFilterConfig {
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue