Skip to content

Commit

Permalink
chore: Add ConditionalOnMissingBean to all beans (#1185)
Browse files Browse the repository at this point in the history
Follow up to #1180
  • Loading branch information
timonback authored Feb 14, 2025
1 parent 4562841 commit 8f721b9
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import io.github.springwolf.addons.generic_binding.annotation.processor.AsyncGenericOperationBindingProcessor;
import io.github.springwolf.core.asyncapi.scanners.bindings.BindingProcessorPriority;
import io.github.springwolf.core.configuration.properties.SpringwolfConfigConstants;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
Expand All @@ -15,6 +16,7 @@
public class SpringwolfGenericBindingAutoConfiguration {

@Bean
@ConditionalOnMissingBean
@Order(value = BindingProcessorPriority.GENERIC_BINDING)
public AsyncGenericOperationBindingProcessor asyncGenericOperationBindingProcessor(
StringValueResolver stringValueResolver) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ public SchemaWalkerProvider schemaWalkerProvider(List<SchemaWalker> schemaWalker
}

@Bean
@ConditionalOnMissingBean(name = "jsonSchemaWalker")
public SchemaWalker jsonSchemaWalker() {
return new DefaultSchemaWalker<>(new ExampleJsonValueGenerator());
}
Expand All @@ -187,6 +188,7 @@ public ExampleXmlValueSerializer defaultExampleXmlValueSerializer() {
}

@Bean
@ConditionalOnMissingBean(name = "xmlSchemaWalker")
public SchemaWalker xmlSchemaWalker(ExampleXmlValueSerializer exampleXmlValueSerializer) {
return new DefaultSchemaWalker<>(new ExampleXmlValueGenerator(exampleXmlValueSerializer));
}
Expand All @@ -198,6 +200,7 @@ public ExampleYamlValueSerializer defaultExampleYamlValueSerializer() {
}

@Bean
@ConditionalOnMissingBean(name = "yamlSchemaWalker")
public SchemaWalker yamlSchemaWalker(
ExampleYamlValueSerializer exampleYamlValueSerializer,
SpringwolfConfigProperties springwolfConfigProperties) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ public SpringwolfClassScanner springwolfClassScanner(
name = SPRINGWOLF_SCANNER_ASYNC_LISTENER_ENABLED,
havingValue = "true",
matchIfMissing = true)
@ConditionalOnMissingBean(name = "asyncListenerMethodLevelAnnotationChannelScanner")
@Order(value = ChannelPriority.ASYNC_ANNOTATION)
public ChannelsScanner asyncListenerMethodLevelAnnotationChannelScanner(
AsyncAnnotationProvider<AsyncListener> asyncAnnotationProvider,
Expand Down Expand Up @@ -101,6 +102,7 @@ public ChannelsScanner asyncListenerMethodLevelAnnotationChannelScanner(
name = SPRINGWOLF_SCANNER_ASYNC_LISTENER_ENABLED,
havingValue = "true",
matchIfMissing = true)
@ConditionalOnMissingBean(name = "asyncListenerClassLevelAnnotationChannelScanner")
@Order(value = ChannelPriority.ASYNC_ANNOTATION)
public ChannelsScanner asyncListenerClassLevelAnnotationChannelScanner(
AsyncAnnotationProvider<AsyncListener> asyncAnnotationProvider,
Expand Down Expand Up @@ -132,6 +134,7 @@ public ChannelsScanner asyncListenerClassLevelAnnotationChannelScanner(
name = SPRINGWOLF_SCANNER_ASYNC_LISTENER_ENABLED,
havingValue = "true",
matchIfMissing = true)
@ConditionalOnMissingBean(name = "asyncListenerMethodLevelAnnotationOperationScanner")
@Order(value = ChannelPriority.ASYNC_ANNOTATION)
public OperationsScanner asyncListenerMethodLevelAnnotationOperationScanner(
AsyncAnnotationProvider<AsyncListener> asyncAnnotationProvider,
Expand All @@ -156,6 +159,7 @@ public OperationsScanner asyncListenerMethodLevelAnnotationOperationScanner(
name = SPRINGWOLF_SCANNER_ASYNC_LISTENER_ENABLED,
havingValue = "true",
matchIfMissing = true)
@ConditionalOnMissingBean(name = "asyncListenerClassLevelListenerAnnotationOperationsScanner")
@Order(value = ChannelPriority.ASYNC_ANNOTATION)
public OperationsScanner asyncListenerClassLevelListenerAnnotationOperationsScanner(
AsyncAnnotationProvider<AsyncListener> asyncAnnotationProvider,
Expand Down Expand Up @@ -184,6 +188,7 @@ public OperationsScanner asyncListenerClassLevelListenerAnnotationOperationsScan
name = SPRINGWOLF_SCANNER_ASYNC_PUBLISHER_ENABLED,
havingValue = "true",
matchIfMissing = true)
@ConditionalOnMissingBean(name = "asyncPublisherClassLevelChannelAnnotationScanner")
@Order(value = ChannelPriority.ASYNC_ANNOTATION)
public ChannelsScanner asyncPublisherClassLevelChannelAnnotationScanner(
AsyncAnnotationProvider<AsyncPublisher> asyncAnnotationProvider,
Expand Down Expand Up @@ -215,6 +220,7 @@ public ChannelsScanner asyncPublisherClassLevelChannelAnnotationScanner(
name = SPRINGWOLF_SCANNER_ASYNC_PUBLISHER_ENABLED,
havingValue = "true",
matchIfMissing = true)
@ConditionalOnMissingBean(name = "asyncPublisherClassLevelAnnotationChannelScanner")
@Order(value = ChannelPriority.ASYNC_ANNOTATION)
public ChannelsScanner asyncPublisherClassLevelAnnotationChannelScanner(
AsyncAnnotationProvider<AsyncPublisher> asyncAnnotationProvider,
Expand Down Expand Up @@ -246,6 +252,7 @@ public ChannelsScanner asyncPublisherClassLevelAnnotationChannelScanner(
name = SPRINGWOLF_SCANNER_ASYNC_PUBLISHER_ENABLED,
havingValue = "true",
matchIfMissing = true)
@ConditionalOnMissingBean(name = "asyncPublisherClassLevelOperationAnnotationScanner")
@Order(value = ChannelPriority.ASYNC_ANNOTATION)
public OperationsScanner asyncPublisherClassLevelOperationAnnotationScanner(
AsyncAnnotationProvider<AsyncPublisher> asyncAnnotationProvider,
Expand All @@ -271,6 +278,7 @@ public OperationsScanner asyncPublisherClassLevelOperationAnnotationScanner(
name = SPRINGWOLF_SCANNER_ASYNC_PUBLISHER_ENABLED,
havingValue = "true",
matchIfMissing = true)
@ConditionalOnMissingBean(name = "asyncPublisherClassLevelListenerAnnotationOperationsScanner")
@Order(value = ChannelPriority.ASYNC_ANNOTATION)
public OperationsScanner asyncPublisherClassLevelListenerAnnotationOperationsScanner(
AsyncAnnotationProvider<AsyncPublisher> asyncAnnotationProvider,
Expand All @@ -295,6 +303,7 @@ public OperationsScanner asyncPublisherClassLevelListenerAnnotationOperationsSca
}

@Bean
@ConditionalOnMissingBean(name = "asyncListenerAnnotationProvider")
public AsyncAnnotationProvider<AsyncListener> asyncListenerAnnotationProvider() {
return new AsyncAnnotationProvider<>() {
@Override
Expand All @@ -315,6 +324,7 @@ public OperationAction getOperationType() {
}

@Bean
@ConditionalOnMissingBean(name = "asyncPublisherAnnotationProvider")
public AsyncAnnotationProvider<AsyncPublisher> asyncPublisherAnnotationProvider() {
return new AsyncAnnotationProvider<>() {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public class SpringwolfAmqpScannerConfiguration {
name = SPRINGWOLF_SCANNER_RABBIT_LISTENER_ENABLED,
havingValue = "true",
matchIfMissing = true)
@ConditionalOnMissingBean(name = "amqpBindingFactory")
@ConditionalOnMissingBean
public AmqpBindingFactory amqpBindingFactory(
List<Queue> queues,
List<Exchange> exchanges,
Expand All @@ -65,7 +65,7 @@ public AmqpBindingFactory amqpBindingFactory(
name = SPRINGWOLF_SCANNER_RABBIT_LISTENER_ENABLED,
havingValue = "true",
matchIfMissing = true)
@ConditionalOnMissingBean(name = "asyncHeadersForAmqpBuilder")
@ConditionalOnMissingBean
public AsyncHeadersForAmqpBuilder asyncHeadersForAmqpBuilder() {
return new AsyncHeadersForAmqpBuilder();
}
Expand Down Expand Up @@ -198,7 +198,7 @@ public OperationsScanner simpleRabbitMethodLevelListenerAnnotationOperationsScan
havingValue = "true",
matchIfMissing = true)
@Order(value = ChannelPriority.AUTO_DISCOVERED)
@ConditionalOnMissingBean(name = "rabbitQueueBeanScanner")
@ConditionalOnMissingBean
public RabbitQueueBeanScanner rabbitQueueBeanScanner(List<Queue> queues, List<Binding> bindings) {
return new RabbitQueueBeanScanner(queues, bindings);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import io.github.springwolf.plugins.cloudstream.asyncapi.scanners.common.FunctionalChannelBeanBuilder;
import io.github.springwolf.plugins.cloudstream.asyncapi.scanners.operations.CloudStreamFunctionOperationsScanner;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.cloud.stream.config.BindingServiceProperties;
import org.springframework.context.annotation.Bean;
Expand All @@ -28,6 +29,7 @@
public class SpringwolfCloudStreamAutoConfiguration {

@Bean
@ConditionalOnMissingBean
public CloudStreamFunctionChannelsScanner cloudStreamFunctionChannelsScanner(
AsyncApiDocketService asyncApiDocketService,
BeanMethodsScanner beanMethodsScanner,
Expand All @@ -51,6 +53,7 @@ public CloudStreamFunctionChannelsScanner cloudStreamFunctionChannelsScanner(
}

@Bean
@ConditionalOnMissingBean
public CloudStreamFunctionOperationsScanner cloudStreamFunctionOperationsScanner(
AsyncApiDocketService asyncApiDocketService,
BeanMethodsScanner beanMethodsScanner,
Expand All @@ -70,6 +73,7 @@ public CloudStreamFunctionOperationsScanner cloudStreamFunctionOperationsScanner
}

@Bean
@ConditionalOnMissingBean
public FunctionalChannelBeanBuilder functionalChannelBeanBuilder(TypeExtractor typeExtractor) {
return new FunctionalChannelBeanBuilder(typeExtractor);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import io.github.springwolf.core.asyncapi.scanners.operations.annotations.SpringAnnotationMethodLevelOperationsScanner;
import io.github.springwolf.plugins.jms.asyncapi.scanners.bindings.JmsBindingFactory;
import lombok.val;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
Expand All @@ -38,12 +39,14 @@ public class SpringwolfJmsScannerConfiguration {

@Bean
@ConditionalOnProperty(name = SPRINGWOLF_SCANNER_JMS_LISTENER_ENABLED, havingValue = "true", matchIfMissing = true)
@ConditionalOnMissingBean
public JmsBindingFactory jmsBindingFactory(StringValueResolver stringValueResolver) {
return new JmsBindingFactory(stringValueResolver);
}

@Bean
@ConditionalOnProperty(name = SPRINGWOLF_SCANNER_JMS_LISTENER_ENABLED, havingValue = "true", matchIfMissing = true)
@ConditionalOnMissingBean(name = "simpleJmsMethodLevelListenerAnnotationChannelsScanner")
@Order(value = ChannelPriority.AUTO_DISCOVERED)
public ChannelsScanner simpleJmsMethodLevelListenerAnnotationChannelsScanner(
SpringwolfClassScanner springwolfClassScanner,
Expand All @@ -67,6 +70,7 @@ public ChannelsScanner simpleJmsMethodLevelListenerAnnotationChannelsScanner(

@Bean
@ConditionalOnProperty(name = SPRINGWOLF_SCANNER_JMS_LISTENER_ENABLED, havingValue = "true", matchIfMissing = true)
@ConditionalOnMissingBean(name = "simpleJmsMethodLevelListenerAnnotationOperationsScanner")
@Order(value = ChannelPriority.AUTO_DISCOVERED)
public OperationsScanner simpleJmsMethodLevelListenerAnnotationOperationsScanner(
SpringwolfClassScanner springwolfClassScanner,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import io.github.springwolf.plugins.kafka.asyncapi.scanners.bindings.KafkaBindingFactory;
import io.github.springwolf.plugins.kafka.asyncapi.scanners.common.header.AsyncHeadersForKafkaBuilder;
import lombok.val;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
Expand All @@ -46,6 +47,7 @@ public class SpringwolfKafkaScannerConfiguration {
name = SPRINGWOLF_SCANNER_KAFKA_LISTENER_ENABLED,
havingValue = "true",
matchIfMissing = true)
@ConditionalOnMissingBean(name = "kafkaBindingFactory")
public KafkaBindingFactory kafkaBindingFactory(StringValueResolver stringValueResolver) {
return new KafkaBindingFactory(stringValueResolver);
}
Expand All @@ -55,6 +57,7 @@ public KafkaBindingFactory kafkaBindingFactory(StringValueResolver stringValueRe
name = SPRINGWOLF_SCANNER_KAFKA_LISTENER_ENABLED,
havingValue = "true",
matchIfMissing = true)
@ConditionalOnMissingBean(name = "asyncHeadersForKafkaBuilder")
public AsyncHeadersForKafkaBuilder asyncHeadersForKafkaBuilder() {
return new AsyncHeadersForKafkaBuilder();
}
Expand All @@ -64,6 +67,7 @@ public AsyncHeadersForKafkaBuilder asyncHeadersForKafkaBuilder() {
name = SPRINGWOLF_SCANNER_KAFKA_LISTENER_ENABLED,
havingValue = "true",
matchIfMissing = true)
@ConditionalOnMissingBean(name = "simpleKafkaClassLevelListenerAnnotationChannelsScanner")
@Order(value = ChannelPriority.AUTO_DISCOVERED)
public ChannelsScanner simpleKafkaClassLevelListenerAnnotationChannelsScanner(
SpringwolfClassScanner springwolfClassScanner,
Expand Down Expand Up @@ -94,6 +98,7 @@ public ChannelsScanner simpleKafkaClassLevelListenerAnnotationChannelsScanner(
name = SPRINGWOLF_SCANNER_KAFKA_LISTENER_ENABLED,
havingValue = "true",
matchIfMissing = true)
@ConditionalOnMissingBean(name = "simpleKafkaClassLevelListenerAnnotationOperationScanner")
@Order(value = ChannelPriority.AUTO_DISCOVERED)
public OperationsScanner simpleKafkaClassLevelListenerAnnotationOperationScanner(
SpringwolfClassScanner springwolfClassScanner,
Expand Down Expand Up @@ -126,6 +131,7 @@ public OperationsScanner simpleKafkaClassLevelListenerAnnotationOperationScanner
name = SPRINGWOLF_SCANNER_KAFKA_LISTENER_ENABLED,
havingValue = "true",
matchIfMissing = true)
@ConditionalOnMissingBean(name = "simpleKafkaMethodLevelListenerAnnotationChannelsScanner")
@Order(value = ChannelPriority.AUTO_DISCOVERED)
public ChannelsScanner simpleKafkaMethodLevelListenerAnnotationChannelsScanner(
SpringwolfClassScanner springwolfClassScanner,
Expand All @@ -152,6 +158,7 @@ public ChannelsScanner simpleKafkaMethodLevelListenerAnnotationChannelsScanner(
name = SPRINGWOLF_SCANNER_KAFKA_LISTENER_ENABLED,
havingValue = "true",
matchIfMissing = true)
@ConditionalOnMissingBean(name = "simpleKafkaMethodLevelListenerAnnotationOperationsScanner")
@Order(value = ChannelPriority.AUTO_DISCOVERED)
public OperationsScanner simpleKafkaMethodLevelListenerAnnotationOperationsScanner(
SpringwolfClassScanner springwolfClassScanner,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import io.github.springwolf.core.asyncapi.scanners.operations.annotations.SpringAnnotationMethodLevelOperationsScanner;
import io.github.springwolf.plugins.sqs.asyncapi.scanners.bindings.SqsBindingFactory;
import lombok.val;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
Expand All @@ -38,12 +39,14 @@ public class SpringwolfSqsScannerConfiguration {

@Bean
@ConditionalOnProperty(name = SPRINGWOLF_SCANNER_SQS_LISTENER_ENABLED, havingValue = "true", matchIfMissing = true)
@ConditionalOnMissingBean
public SqsBindingFactory sqsBindingFactory(StringValueResolver stringValueResolver) {
return new SqsBindingFactory(stringValueResolver);
}

@Bean
@ConditionalOnProperty(name = SPRINGWOLF_SCANNER_SQS_LISTENER_ENABLED, havingValue = "true", matchIfMissing = true)
@ConditionalOnMissingBean(name = "simpleSqsMethodLevelListenerAnnotationChannelsScanner")
@Order(value = ChannelPriority.AUTO_DISCOVERED)
public ChannelsScanner simpleSqsMethodLevelListenerAnnotationChannelsScanner(
SpringwolfClassScanner springwolfClassScanner,
Expand All @@ -66,6 +69,7 @@ public ChannelsScanner simpleSqsMethodLevelListenerAnnotationChannelsScanner(

@Bean
@ConditionalOnProperty(name = SPRINGWOLF_SCANNER_SQS_LISTENER_ENABLED, havingValue = "true", matchIfMissing = true)
@ConditionalOnMissingBean(name = "simpleSqsMethodLevelListenerAnnotationOperationsScanner")
@Order(value = ChannelPriority.AUTO_DISCOVERED)
public OperationsScanner simpleSqsMethodLevelListenerAnnotationOperationsScanner(
SpringwolfClassScanner springwolfClassScanner,
Expand Down
Loading

0 comments on commit 8f721b9

Please sign in to comment.