From 3b14e6a1f7fa47a3db4b68cfcde18f80856194f9 Mon Sep 17 00:00:00 2001 From: Christoffer Sawicki Date: Sun, 6 Nov 2016 20:03:34 +0100 Subject: [PATCH] Allow TraceWebAutoConfiguration to work without Web MVC Fixes #436 --- .../instrument/web/TraceWebAutoConfiguration.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/instrument/web/TraceWebAutoConfiguration.java b/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/instrument/web/TraceWebAutoConfiguration.java index baa88e189..256af8b9c 100644 --- a/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/instrument/web/TraceWebAutoConfiguration.java +++ b/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/instrument/web/TraceWebAutoConfiguration.java @@ -38,6 +38,7 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; import org.springframework.util.StringUtils; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; import static javax.servlet.DispatcherType.ASYNC; import static javax.servlet.DispatcherType.ERROR; @@ -61,7 +62,6 @@ import static javax.servlet.DispatcherType.REQUEST; @ConditionalOnBean(Tracer.class) @AutoConfigureAfter(TraceAutoConfiguration.class) @EnableConfigurationProperties(TraceKeys.class) -@Import(TraceWebMvcConfigurer.class) public class TraceWebAutoConfiguration { /** @@ -70,6 +70,16 @@ public class TraceWebAutoConfiguration { @Value("${spring.sleuth.web.skipPattern:}") private String skipPattern; + /** + * Nested config that configures Web MVC if it's present + * (without adding a runtime dependency to it) + */ + @Configuration + @ConditionalOnClass(WebMvcConfigurerAdapter.class) + @Import(TraceWebMvcConfigurer.class) + protected static class TraceWebMvcAutoConfiguration { + } + @Bean public TraceWebAspect traceWebAspect(Tracer tracer, SpanNamer spanNamer) { return new TraceWebAspect(tracer, spanNamer);