Ref: Tracking down cause of Spring's "not * eligible for auto-proxying"
*/ - private BeanFactory beanFactory; + BeanFactory beanFactory; @Override public Object postProcessAfterInitialization(Object bean, String beanName) { if (bean instanceof StorageComponent) { @@ -74,7 +72,7 @@ static class ThrottledStorageComponentEnhancer implements BeanPostProcessor, Bea beanFactory.getBean(ZipkinStorageThrottleProperties.class); return new ThrottledStorageComponent((StorageComponent) bean, beanFactory.getBean(MeterRegistry.class), - tracing, + beanFactory.containsBean("tracing") ? beanFactory.getBean(Tracing.class) : null, throttleProperties.getMinConcurrency(), throttleProperties.getMaxConcurrency(), throttleProperties.getMaxQueueSize()); @@ -87,33 +85,37 @@ static class ThrottledStorageComponentEnhancer implements BeanPostProcessor, Bea } } - @Configuration @ConditionalOnSelfTracing - static class TracingStorageComponentEnhancer implements BeanPostProcessor { - - @Autowired(required = false) - Tracing tracing; + static class TracingStorageComponentEnhancer implements BeanPostProcessor, BeanFactoryAware { + /** + * Need this to resolve cyclic instantiation issue with spring when instantiating with tracing. + * + *Ref: Tracking down cause of Spring's "not + * eligible for auto-proxying"
+ */ + BeanFactory beanFactory; - @Override - public Object postProcessBeforeInitialization(Object bean, String beanName) { + @Override public Object postProcessBeforeInitialization(Object bean, String beanName) { return bean; } - @Override - public Object postProcessAfterInitialization(Object bean, String beanName) { - if (tracing == null) return bean; - if (bean instanceof StorageComponent) { + @Override public Object postProcessAfterInitialization(Object bean, String beanName) { + if (bean instanceof StorageComponent && beanFactory.containsBean("tracing")) { + Tracing tracing = beanFactory.getBean(Tracing.class); return new TracingStorageComponent(tracing, (StorageComponent) bean); } return bean; } + + @Override public void setBeanFactory(BeanFactory beanFactory) throws BeansException { + this.beanFactory = beanFactory; + } } /** * This is a special-case configuration if there's no StorageComponent of any kind. In-Mem can * supply both read apis, so we add two beans here. */ - @Configuration @Conditional(StorageTypeMemAbsentOrEmpty.class) @ConditionalOnMissingBean(StorageComponent.class) static class InMemoryConfiguration { diff --git a/zipkin-server/src/main/java/zipkin2/server/internal/ZipkinHttpConfiguration.java b/zipkin-server/src/main/java/zipkin2/server/internal/ZipkinHttpConfiguration.java index 49f7e50fdeb..c3ac535b51b 100644 --- a/zipkin-server/src/main/java/zipkin2/server/internal/ZipkinHttpConfiguration.java +++ b/zipkin-server/src/main/java/zipkin2/server/internal/ZipkinHttpConfiguration.java @@ -33,7 +33,7 @@ import zipkin2.server.internal.health.ZipkinHealthController; import zipkin2.server.internal.prometheus.ZipkinMetricsController; -@Configuration +@Configuration(proxyBeanMethods=false) public class ZipkinHttpConfiguration { public static final MediaType MEDIA_TYPE_ACTUATOR = MediaType.parse("application/vnd.spring-boot.actuator.v2+json;charset=UTF-8"); diff --git a/zipkin-server/src/main/java/zipkin2/server/internal/activemq/ZipkinActiveMQCollectorConfiguration.java b/zipkin-server/src/main/java/zipkin2/server/internal/activemq/ZipkinActiveMQCollectorConfiguration.java index f7a8ad77509..837ca04e48e 100644 --- a/zipkin-server/src/main/java/zipkin2/server/internal/activemq/ZipkinActiveMQCollectorConfiguration.java +++ b/zipkin-server/src/main/java/zipkin2/server/internal/activemq/ZipkinActiveMQCollectorConfiguration.java @@ -19,7 +19,6 @@ import org.springframework.context.annotation.Condition; import org.springframework.context.annotation.ConditionContext; import org.springframework.context.annotation.Conditional; -import org.springframework.context.annotation.Configuration; import org.springframework.core.type.AnnotatedTypeMetadata; import zipkin2.collector.CollectorMetrics; import zipkin2.collector.CollectorSampler; @@ -27,7 +26,6 @@ import zipkin2.storage.StorageComponent; /** Auto-configuration for {@link ActiveMQCollector}. */ -@Configuration @ConditionalOnClass(ActiveMQCollector.class) @EnableConfigurationProperties(ZipkinActiveMQCollectorProperties.class) @Conditional(ZipkinActiveMQCollectorConfiguration.ActiveMQUrlSet.class) diff --git a/zipkin-server/src/main/java/zipkin2/server/internal/brave/ZipkinSelfTracingConfiguration.java b/zipkin-server/src/main/java/zipkin2/server/internal/brave/ZipkinSelfTracingConfiguration.java index c79f46cbb6d..b3089a256d2 100644 --- a/zipkin-server/src/main/java/zipkin2/server/internal/brave/ZipkinSelfTracingConfiguration.java +++ b/zipkin-server/src/main/java/zipkin2/server/internal/brave/ZipkinSelfTracingConfiguration.java @@ -31,7 +31,6 @@ import org.springframework.beans.factory.BeanFactory; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; import zipkin2.Call; import zipkin2.CheckResult; import zipkin2.Span; @@ -45,7 +44,6 @@ import zipkin2.server.internal.ConditionalOnSelfTracing; import zipkin2.storage.StorageComponent; -@Configuration @EnableConfigurationProperties(SelfTracingProperties.class) @ConditionalOnSelfTracing public class ZipkinSelfTracingConfiguration { diff --git a/zipkin-server/src/main/java/zipkin2/server/internal/cassandra/ZipkinCassandraStorageConfiguration.java b/zipkin-server/src/main/java/zipkin2/server/internal/cassandra/ZipkinCassandraStorageConfiguration.java index 2a3e52c4ad6..11d22cc77f4 100644 --- a/zipkin-server/src/main/java/zipkin2/server/internal/cassandra/ZipkinCassandraStorageConfiguration.java +++ b/zipkin-server/src/main/java/zipkin2/server/internal/cassandra/ZipkinCassandraStorageConfiguration.java @@ -16,7 +16,9 @@ import brave.Tracing; import brave.cassandra.driver.TracingSession; import java.util.List; -import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.BeansException; +import org.springframework.beans.factory.BeanFactory; +import org.springframework.beans.factory.BeanFactoryAware; import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.config.BeanPostProcessor; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; @@ -24,7 +26,7 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Import; import zipkin2.server.internal.ConditionalOnSelfTracing; import zipkin2.storage.StorageComponent; import zipkin2.storage.cassandra.v1.CassandraStorage; @@ -35,11 +37,11 @@ * contain a single span, which is TBinaryProtocol big-endian, then base64 encoded. Decoded spans * are stored asynchronously. */ -@Configuration @ConditionalOnClass(CassandraStorage.class) @EnableConfigurationProperties(ZipkinCassandraStorageProperties.class) @ConditionalOnProperty(name = "zipkin.storage.type", havingValue = "cassandra") @ConditionalOnMissingBean(StorageComponent.class) +@Import(ZipkinCassandraStorageConfiguration.TracingSessionFactoryEnhancer.class) public class ZipkinCassandraStorageConfiguration { @Bean SessionFactory sessionFactory() { @@ -65,23 +67,31 @@ StorageComponent storage( .sessionFactory(sessionFactory).build(); } - @Configuration @ConditionalOnSelfTracing - static class TracingSessionFactoryEnhancer implements BeanPostProcessor { - - @Autowired(required = false) Tracing tracing; + static class TracingSessionFactoryEnhancer implements BeanPostProcessor, BeanFactoryAware { + /** + * Need this to resolve cyclic instantiation issue with spring when instantiating with tracing. + * + *Ref: Tracking down cause of Spring's "not + * eligible for auto-proxying"
+ */ + BeanFactory beanFactory; @Override public Object postProcessBeforeInitialization(Object bean, String beanName) { return bean; } @Override public Object postProcessAfterInitialization(Object bean, String beanName) { - if (tracing == null) return bean; - if (bean instanceof SessionFactory) { + if (bean instanceof SessionFactory && beanFactory.containsBean("tracing")) { SessionFactory delegate = (SessionFactory) bean; + Tracing tracing = beanFactory.getBean(Tracing.class); return (SessionFactory) storage -> TracingSession.create(tracing, delegate.create(storage)); } return bean; } + + @Override public void setBeanFactory(BeanFactory beanFactory) throws BeansException { + this.beanFactory = beanFactory; + } } } diff --git a/zipkin-server/src/main/java/zipkin2/server/internal/cassandra3/ZipkinCassandra3StorageConfiguration.java b/zipkin-server/src/main/java/zipkin2/server/internal/cassandra3/ZipkinCassandra3StorageConfiguration.java index 4b427dea5c1..04dbe834b8c 100644 --- a/zipkin-server/src/main/java/zipkin2/server/internal/cassandra3/ZipkinCassandra3StorageConfiguration.java +++ b/zipkin-server/src/main/java/zipkin2/server/internal/cassandra3/ZipkinCassandra3StorageConfiguration.java @@ -16,7 +16,9 @@ import brave.Tracing; import brave.cassandra.driver.TracingSession; import java.util.List; -import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.BeansException; +import org.springframework.beans.factory.BeanFactory; +import org.springframework.beans.factory.BeanFactoryAware; import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.config.BeanPostProcessor; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; @@ -24,7 +26,7 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Import; import zipkin2.server.internal.ConditionalOnSelfTracing; import zipkin2.storage.StorageComponent; import zipkin2.storage.cassandra.CassandraStorage; @@ -35,11 +37,11 @@ * contain a single span, which is TBinaryProtocol big-endian, then base64 encoded. Decoded spans * are stored asynchronously. */ -@Configuration @ConditionalOnClass(CassandraStorage.class) @EnableConfigurationProperties(ZipkinCassandra3StorageProperties.class) @ConditionalOnProperty(name = "zipkin.storage.type", havingValue = "cassandra3") @ConditionalOnMissingBean(StorageComponent.class) +@Import(ZipkinCassandra3StorageConfiguration.TracingSessionFactoryEnhancer.class) // This component is named .*Cassandra3.* even though the package already says cassandra3 because // Spring Boot configuration endpoints only printout the simple name of the class public class ZipkinCassandra3StorageConfiguration { @@ -67,23 +69,31 @@ StorageComponent storage( .sessionFactory(sessionFactory).build(); } - @Configuration @ConditionalOnSelfTracing - static class TracingSessionFactoryEnhancer implements BeanPostProcessor { - - @Autowired(required = false) Tracing tracing; + static class TracingSessionFactoryEnhancer implements BeanPostProcessor, BeanFactoryAware { + /** + * Need this to resolve cyclic instantiation issue with spring when instantiating with tracing. + * + *Ref: Tracking down cause of Spring's "not + * eligible for auto-proxying"
+ */ + BeanFactory beanFactory; @Override public Object postProcessBeforeInitialization(Object bean, String beanName) { return bean; } @Override public Object postProcessAfterInitialization(Object bean, String beanName) { - if (tracing == null) return bean; - if (bean instanceof SessionFactory) { + if (bean instanceof SessionFactory && beanFactory.containsBean("tracing")) { SessionFactory delegate = (SessionFactory) bean; + Tracing tracing = beanFactory.getBean(Tracing.class); return (SessionFactory) storage -> TracingSession.create(tracing, delegate.create(storage)); } return bean; } + + @Override public void setBeanFactory(BeanFactory beanFactory) throws BeansException { + this.beanFactory = beanFactory; + } } } diff --git a/zipkin-server/src/main/java/zipkin2/server/internal/elasticsearch/ZipkinElasticsearchStorageConfiguration.java b/zipkin-server/src/main/java/zipkin2/server/internal/elasticsearch/ZipkinElasticsearchStorageConfiguration.java index f77a5a3acc4..621183c0b94 100644 --- a/zipkin-server/src/main/java/zipkin2/server/internal/elasticsearch/ZipkinElasticsearchStorageConfiguration.java +++ b/zipkin-server/src/main/java/zipkin2/server/internal/elasticsearch/ZipkinElasticsearchStorageConfiguration.java @@ -47,7 +47,7 @@ import static zipkin2.server.internal.elasticsearch.ZipkinElasticsearchStorageProperties.Ssl; -@Configuration +@Configuration(proxyBeanMethods=false) @EnableConfigurationProperties(ZipkinElasticsearchStorageProperties.class) @ConditionalOnProperty(name = "zipkin.storage.type", havingValue = "elasticsearch") @ConditionalOnMissingBean(StorageComponent.class) diff --git a/zipkin-server/src/main/java/zipkin2/server/internal/kafka/ZipkinKafkaCollectorConfiguration.java b/zipkin-server/src/main/java/zipkin2/server/internal/kafka/ZipkinKafkaCollectorConfiguration.java index 7b2b0b336c5..93fdbacb3bb 100644 --- a/zipkin-server/src/main/java/zipkin2/server/internal/kafka/ZipkinKafkaCollectorConfiguration.java +++ b/zipkin-server/src/main/java/zipkin2/server/internal/kafka/ZipkinKafkaCollectorConfiguration.java @@ -19,7 +19,6 @@ import org.springframework.context.annotation.Condition; import org.springframework.context.annotation.ConditionContext; import org.springframework.context.annotation.Conditional; -import org.springframework.context.annotation.Configuration; import org.springframework.core.type.AnnotatedTypeMetadata; import zipkin2.collector.CollectorMetrics; import zipkin2.collector.CollectorSampler; @@ -30,7 +29,6 @@ * This collector consumes a topic, decodes spans from thrift messages and stores them subject to * sampling policy. */ -@Configuration @ConditionalOnClass(KafkaCollector.class) @Conditional(ZipkinKafkaCollectorConfiguration.KafkaBootstrapServersSet.class) @EnableConfigurationProperties(ZipkinKafkaCollectorProperties.class) diff --git a/zipkin-server/src/main/java/zipkin2/server/internal/mysql/ZipkinMySQLStorageConfiguration.java b/zipkin-server/src/main/java/zipkin2/server/internal/mysql/ZipkinMySQLStorageConfiguration.java index bd12c121c06..e3a6f538544 100644 --- a/zipkin-server/src/main/java/zipkin2/server/internal/mysql/ZipkinMySQLStorageConfiguration.java +++ b/zipkin-server/src/main/java/zipkin2/server/internal/mysql/ZipkinMySQLStorageConfiguration.java @@ -24,13 +24,11 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; import zipkin2.storage.StorageComponent; import zipkin2.storage.mysql.v1.MySQLStorage; -@Configuration @EnableConfigurationProperties(ZipkinMySQLStorageProperties.class) @ConditionalOnClass(MySQLStorage.class) @ConditionalOnProperty(name = "zipkin.storage.type", havingValue = "mysql") diff --git a/zipkin-server/src/main/java/zipkin2/server/internal/mysql/ZipkinSelfTracingMySQLStorageConfiguration.java b/zipkin-server/src/main/java/zipkin2/server/internal/mysql/ZipkinSelfTracingMySQLStorageConfiguration.java index 0781041f446..d307b08023a 100644 --- a/zipkin-server/src/main/java/zipkin2/server/internal/mysql/ZipkinSelfTracingMySQLStorageConfiguration.java +++ b/zipkin-server/src/main/java/zipkin2/server/internal/mysql/ZipkinSelfTracingMySQLStorageConfiguration.java @@ -25,13 +25,11 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; import zipkin2.server.internal.ConditionalOnSelfTracing; /** Sets up the MySQL tracing in Brave as an initialization. */ @ConditionalOnSelfTracing @ConditionalOnProperty(name = "zipkin.storage.type", havingValue = "mysql") -@Configuration class ZipkinSelfTracingMySQLStorageConfiguration extends DefaultExecuteListener { @Autowired ZipkinMySQLStorageProperties mysql; diff --git a/zipkin-server/src/main/java/zipkin2/server/internal/prometheus/ZipkinPrometheusMetricsConfiguration.java b/zipkin-server/src/main/java/zipkin2/server/internal/prometheus/ZipkinPrometheusMetricsConfiguration.java index ccde99688a4..03e5e30338c 100644 --- a/zipkin-server/src/main/java/zipkin2/server/internal/prometheus/ZipkinPrometheusMetricsConfiguration.java +++ b/zipkin-server/src/main/java/zipkin2/server/internal/prometheus/ZipkinPrometheusMetricsConfiguration.java @@ -42,7 +42,7 @@ import org.springframework.core.annotation.Order; import org.springframework.util.StringUtils; -@Configuration +@Configuration(proxyBeanMethods=false) public class ZipkinPrometheusMetricsConfiguration { // from io.micrometer.spring.web.servlet.WebMvcTags private static final Tag URI_NOT_FOUND = Tag.of("uri", "NOT_FOUND"); diff --git a/zipkin-server/src/main/java/zipkin2/server/internal/rabbitmq/ZipkinRabbitMQCollectorConfiguration.java b/zipkin-server/src/main/java/zipkin2/server/internal/rabbitmq/ZipkinRabbitMQCollectorConfiguration.java index cd47365499f..888798e4f42 100644 --- a/zipkin-server/src/main/java/zipkin2/server/internal/rabbitmq/ZipkinRabbitMQCollectorConfiguration.java +++ b/zipkin-server/src/main/java/zipkin2/server/internal/rabbitmq/ZipkinRabbitMQCollectorConfiguration.java @@ -22,7 +22,6 @@ import org.springframework.context.annotation.Condition; import org.springframework.context.annotation.ConditionContext; import org.springframework.context.annotation.Conditional; -import org.springframework.context.annotation.Configuration; import org.springframework.core.type.AnnotatedTypeMetadata; import zipkin2.collector.CollectorMetrics; import zipkin2.collector.CollectorSampler; @@ -30,7 +29,6 @@ import zipkin2.storage.StorageComponent; /** Auto-configuration for {@link RabbitMQCollector}. */ -@Configuration @ConditionalOnClass(RabbitMQCollector.class) @Conditional(ZipkinRabbitMQCollectorConfiguration.RabbitMQAddressesOrUriSet.class) @EnableConfigurationProperties(ZipkinRabbitMQCollectorProperties.class) diff --git a/zipkin-server/src/main/java/zipkin2/server/internal/scribe/ZipkinScribeCollectorConfiguration.java b/zipkin-server/src/main/java/zipkin2/server/internal/scribe/ZipkinScribeCollectorConfiguration.java index adde9f31234..87cee440d02 100644 --- a/zipkin-server/src/main/java/zipkin2/server/internal/scribe/ZipkinScribeCollectorConfiguration.java +++ b/zipkin-server/src/main/java/zipkin2/server/internal/scribe/ZipkinScribeCollectorConfiguration.java @@ -17,7 +17,6 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; import zipkin2.collector.CollectorMetrics; import zipkin2.collector.CollectorSampler; import zipkin2.collector.scribe.ScribeCollector; @@ -28,7 +27,6 @@ * a single span, which is TBinaryProtocol big-endian, then base64 encoded. Decoded spans are stored * asynchronously. */ -@Configuration @ConditionalOnClass(ScribeCollector.class) @ConditionalOnProperty(value = "zipkin.collector.scribe.enabled", havingValue = "true") public class ZipkinScribeCollectorConfiguration { diff --git a/zipkin-server/src/main/java/zipkin2/server/internal/ui/ZipkinUiConfiguration.java b/zipkin-server/src/main/java/zipkin2/server/internal/ui/ZipkinUiConfiguration.java index 6512deafbba..3dd9b0564ab 100644 --- a/zipkin-server/src/main/java/zipkin2/server/internal/ui/ZipkinUiConfiguration.java +++ b/zipkin-server/src/main/java/zipkin2/server/internal/ui/ZipkinUiConfiguration.java @@ -46,7 +46,6 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; import org.springframework.core.io.Resource; import org.springframework.util.StreamUtils; import zipkin2.server.internal.JsonUtil; @@ -76,7 +75,6 @@ * Since index.html links to hashed resource names, any change to it will orphan old resources. * That's why hashed resource age can be 365 days. */ -@Configuration @EnableConfigurationProperties({ZipkinUiProperties.class, CompressionProperties.class}) @ConditionalOnProperty(name = "zipkin.ui.enabled", matchIfMissing = true) public class ZipkinUiConfiguration { diff --git a/zipkin-server/src/test/java/zipkin2/server/internal/brave/ITZipkinSelfTracing.java b/zipkin-server/src/test/java/zipkin2/server/internal/brave/ITZipkinSelfTracing.java index 4d388579e0f..90fb26c35c0 100644 --- a/zipkin-server/src/test/java/zipkin2/server/internal/brave/ITZipkinSelfTracing.java +++ b/zipkin-server/src/test/java/zipkin2/server/internal/brave/ITZipkinSelfTracing.java @@ -32,7 +32,7 @@ import zipkin2.Component; import zipkin2.Span; import zipkin2.codec.SpanBytesEncoder; -import zipkin2.reporter.AsyncReporter; +import zipkin2.reporter.Reporter; import zipkin2.storage.InMemoryStorage; import zipkin2.storage.QueryRequest; @@ -60,7 +60,7 @@ @RunWith(SpringRunner.class) public class ITZipkinSelfTracing { @Autowired TracingStorageComponent storage; - @Autowired AsyncReporter reporter; + @Autowired Reporter reporter; @Autowired Server server; OkHttpClient client = new OkHttpClient.Builder().followRedirects(false).build(); diff --git a/zipkin-storage/cassandra-v1/src/test/java/zipkin2/storage/cassandra/v1/ITCassandraStorage.java b/zipkin-storage/cassandra-v1/src/test/java/zipkin2/storage/cassandra/v1/ITCassandraStorage.java index faf732f0ae9..aca9149bd04 100644 --- a/zipkin-storage/cassandra-v1/src/test/java/zipkin2/storage/cassandra/v1/ITCassandraStorage.java +++ b/zipkin-storage/cassandra-v1/src/test/java/zipkin2/storage/cassandra/v1/ITCassandraStorage.java @@ -43,7 +43,7 @@ class ITCassandraStorage { @RegisterExtension CassandraStorageExtension backend = - new CassandraStorageExtension("openzipkin/zipkin-cassandra:2.17.1"); + new CassandraStorageExtension("openzipkin/zipkin-cassandra:2.18.2"); @Nested class ITTraces extends zipkin2.storage.ITTraces