Added conditional on class for web auto configuration; fixes gh-1790
This commit is contained in:
@@ -44,6 +44,7 @@ import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
|
||||
|
||||
/**
|
||||
* {@link org.springframework.boot.autoconfigure.EnableAutoConfiguration
|
||||
@@ -61,6 +62,7 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
@ConditionalOnWebApplication(type = ConditionalOnWebApplication.Type.SERVLET)
|
||||
@ConditionalOnBean(HttpTracing.class)
|
||||
@AutoConfigureAfter(TraceHttpAutoConfiguration.class)
|
||||
@ConditionalOnClass(HandlerInterceptorAdapter.class)
|
||||
@Import(SpanCustomizingAsyncHandlerInterceptor.class)
|
||||
public class TraceWebServletAutoConfiguration {
|
||||
|
||||
|
||||
@@ -19,8 +19,10 @@ package org.springframework.cloud.sleuth.instrument.web;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.boot.autoconfigure.AutoConfigurations;
|
||||
import org.springframework.boot.test.context.FilteredClassLoader;
|
||||
import org.springframework.boot.test.context.runner.WebApplicationContextRunner;
|
||||
import org.springframework.cloud.sleuth.autoconfig.TraceAutoConfiguration;
|
||||
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@@ -36,6 +38,20 @@ public class TraceWebServletAutoConfigurationTests {
|
||||
TraceHttpAutoConfiguration.class, TraceWebAutoConfiguration.class,
|
||||
TraceWebServletAutoConfiguration.class));
|
||||
|
||||
@Test
|
||||
public void shouldNotCreateTracedWebBeansWhenServletClassMissing() {
|
||||
this.contextRunner.withClassLoader(new FilteredClassLoader(HandlerInterceptorAdapter.class)).run((context) -> {
|
||||
assertThat(context).doesNotHaveBean(TraceWebAspect.class);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldCreateTracedWebBeansWhenServletClassNotMissing() {
|
||||
this.contextRunner.run((context) -> {
|
||||
assertThat(context).hasSingleBean(TraceWebAspect.class);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldNotCreateExceptionLoggingFilterBeanByDefault() {
|
||||
this.contextRunner.run((context) -> {
|
||||
|
||||
Reference in New Issue
Block a user