Moved more beans to the conditional on backward compatibility autoconfig; fixes gh-1555

This commit is contained in:
Marcin Grzejszczak
2020-02-18 12:22:13 +01:00
parent 20ca616b69
commit eff71d4f22
2 changed files with 46 additions and 38 deletions

View File

@@ -64,6 +64,23 @@ import org.springframework.util.Assert;
@Deprecated @Deprecated
public class ZipkinBackwardsCompatibilityAutoConfiguration { public class ZipkinBackwardsCompatibilityAutoConfiguration {
/**
* Only used for creating a reporter bean with the method below.
* @param zipkinProperties zipkin properties
* @return bytes encoder
* @deprecated left for backwards compatibility
*/
@Bean
@ConditionalOnMissingBean
@Deprecated
BytesEncoder<Span> spanBytesEncoder(ZipkinProperties zipkinProperties) {
return zipkinProperties.getEncoder();
}
@Configuration(proxyBeanMethods = false)
@Conditional(BackwardsCompatibilityCondition.class)
static class BackwardsCompatibilityConfiguration {
/** /**
* Reporter that is depending on a {@link Sender} bean which is created in another * Reporter that is depending on a {@link Sender} bean which is created in another
* auto-configuration than {@link ZipkinAutoConfiguration}. * auto-configuration than {@link ZipkinAutoConfiguration}.
@@ -75,10 +92,10 @@ public class ZipkinBackwardsCompatibilityAutoConfiguration {
* @deprecated left for backwards compatibility * @deprecated left for backwards compatibility
*/ */
@Bean @Bean
@Conditional(BackwardsCompatibilityCondition.class)
@Deprecated @Deprecated
Reporter<Span> reporter(ReporterMetrics reporterMetrics, ZipkinProperties zipkin, Reporter<Span> reporter(ReporterMetrics reporterMetrics, ZipkinProperties zipkin,
BytesEncoder<Span> spanBytesEncoder, DefaultListableBeanFactory beanFactory) { BytesEncoder<Span> spanBytesEncoder,
DefaultListableBeanFactory beanFactory) {
List<String> beanNames = new ArrayList<>( List<String> beanNames = new ArrayList<>(
Arrays.asList(beanFactory.getBeanNamesForType(Sender.class))); Arrays.asList(beanFactory.getBeanNamesForType(Sender.class)));
beanNames.remove(ZipkinAutoConfiguration.SENDER_BEAN_NAME); beanNames.remove(ZipkinAutoConfiguration.SENDER_BEAN_NAME);
@@ -89,19 +106,6 @@ public class ZipkinBackwardsCompatibilityAutoConfiguration {
.metrics(reporterMetrics).build(spanBytesEncoder); .metrics(reporterMetrics).build(spanBytesEncoder);
} }
/**
* Only used for creating a reporter bean with the method above.
* @param zipkinProperties zipkin properties
* @return bytes encoder
* @deprecated left for backwards compatibility
*/
@Bean
@ConditionalOnMissingBean
@Deprecated
BytesEncoder<Span> spanBytesEncoder(ZipkinProperties zipkinProperties) {
return zipkinProperties.getEncoder();
}
/** /**
* Deprecated because this is moved to {@link TraceAutoConfiguration}. Left for * Deprecated because this is moved to {@link TraceAutoConfiguration}. Left for
* backwards compatibility reasons. * backwards compatibility reasons.
@@ -115,6 +119,8 @@ public class ZipkinBackwardsCompatibilityAutoConfiguration {
return new InMemoryReporterMetrics(); return new InMemoryReporterMetrics();
} }
}
/** /**
* Old approach: - one sender - one reporter * Old approach: - one sender - one reporter
* *

View File

@@ -18,6 +18,7 @@ package org.springframework.cloud.sleuth.zipkin2;
import org.junit.Test; import org.junit.Test;
import zipkin2.codec.BytesEncoder; import zipkin2.codec.BytesEncoder;
import zipkin2.reporter.InMemoryReporterMetrics;
import zipkin2.reporter.Reporter; import zipkin2.reporter.Reporter;
import zipkin2.reporter.ReporterMetrics; import zipkin2.reporter.ReporterMetrics;
@@ -43,7 +44,8 @@ public class ZipkinBackwardsCompatibilityAutoConfigurationTests {
assertThat(context.getBean(ZipkinProperties.class)).isNotNull(); assertThat(context.getBean(ZipkinProperties.class)).isNotNull();
assertThat(context.getBean(Reporter.class)).isNotNull(); assertThat(context.getBean(Reporter.class)).isNotNull();
assertThat(context.getBean(BytesEncoder.class)).isNotNull(); assertThat(context.getBean(BytesEncoder.class)).isNotNull();
assertThat(context.getBean(ReporterMetrics.class)).isNotNull(); assertThat(context.getBean(ReporterMetrics.class))
.isInstanceOf(InMemoryReporterMetrics.class);
}); });
} }