Skip to content

Commit

Permalink
added ConditionalOnMissingBean to alle @bean definitions except chann…
Browse files Browse the repository at this point in the history
…elscanner beans. (#413)
  • Loading branch information
tvahrst authored Oct 27, 2023
1 parent 52663b6 commit d76ecb1
Show file tree
Hide file tree
Showing 11 changed files with 38 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,14 @@ public SpringwolfConfigProperties springwolfConfigProperties() {
}

@Bean
@ConditionalOnMissingBean
public SpringwolfInitApplicationListener springwolfInitApplicationListener(
AsyncApiService asyncApiService, SpringwolfConfigProperties configProperties) {
return new SpringwolfInitApplicationListener(asyncApiService, configProperties);
}

@Bean
@ConditionalOnMissingBean
public AsyncApiService asyncApiService(
AsyncApiDocketService asyncApiDocketService,
ChannelsService channelsService,
Expand All @@ -58,16 +60,19 @@ public AsyncApiService asyncApiService(
}

@Bean
@ConditionalOnMissingBean
public ChannelsService channelsService(List<? extends ChannelsScanner> channelsScanners) {
return new DefaultChannelsService(channelsScanners);
}

@Bean
@ConditionalOnMissingBean
public SchemasService schemasService(List<ModelConverter> modelConverters, ExampleGenerator exampleGenerator) {
return new DefaultSchemasService(modelConverters, exampleGenerator);
}

@Bean
@ConditionalOnMissingBean
public AsyncApiDocketService asyncApiDocketService(
Optional<AsyncApiDocket> optionalAsyncApiDocket, SpringwolfConfigProperties springwolfConfigProperties) {
return new DefaultAsyncApiDocketService(optionalAsyncApiDocket, springwolfConfigProperties);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import io.github.stavshamir.springwolf.asyncapi.scanners.classes.ConfigurationClassScanner;
import io.github.stavshamir.springwolf.configuration.AsyncApiDocketService;
import io.github.stavshamir.springwolf.schemas.SchemasService;
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 @@ -34,18 +35,21 @@
public class SpringwolfScannerConfiguration {

@Bean
@ConditionalOnMissingBean
public ComponentClassScanner componentClassScanner(
AsyncApiDocketService asyncApiDocketService, Environment environment) {
return new ComponentClassScanner(asyncApiDocketService, environment);
}

@Bean
@ConditionalOnMissingBean
public ConfigurationClassScanner configurationClassScanner(
AsyncApiDocketService asyncApiDocketService, Environment environment) {
return new ConfigurationClassScanner(asyncApiDocketService, environment);
}

@Bean
@ConditionalOnMissingBean
public BeanMethodsScanner beanMethodsScanner(ConfigurationClassScanner configurationClassScanner) {
return new DefaultBeanMethodsScanner(configurationClassScanner);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import io.github.stavshamir.springwolf.asyncapi.DefaultAsyncApiSerializerService;
import io.github.stavshamir.springwolf.asyncapi.controller.ActuatorAsyncApiController;
import io.github.stavshamir.springwolf.asyncapi.controller.AsyncApiController;
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 @@ -20,19 +21,22 @@ public class SpringwolfWebConfiguration {

@Bean
@ConditionalOnProperty(name = SPRINGWOLF_ENDPOINT_ACTUATOR_ENABLED, havingValue = "false", matchIfMissing = true)
@ConditionalOnMissingBean
public AsyncApiController asyncApiController(
AsyncApiService asyncApiService, AsyncApiSerializerService asyncApiSerializerService) {
return new AsyncApiController(asyncApiService, asyncApiSerializerService);
}

@Bean
@ConditionalOnProperty(name = SPRINGWOLF_ENDPOINT_ACTUATOR_ENABLED, havingValue = "true")
@ConditionalOnMissingBean
public ActuatorAsyncApiController actuatorAsyncApiController(
AsyncApiService asyncApiService, AsyncApiSerializerService asyncApiSerializerService) {
return new ActuatorAsyncApiController(asyncApiService, asyncApiSerializerService);
}

@Bean
@ConditionalOnMissingBean
public AsyncApiSerializerService asyncApiSerializerService() {
return new DefaultAsyncApiSerializerService();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import io.github.stavshamir.springwolf.configuration.AsyncApiDocketService;
import io.github.stavshamir.springwolf.producer.SpringwolfAmqpProducer;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
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 @@ -27,12 +28,14 @@
public class SpringwolfAmqpProducerConfiguration {

@Bean
@ConditionalOnMissingBean
public SpringwolfAmqpProducer springwolfAmqpProducer(
AsyncApiService asyncApiService, @NonNull List<RabbitTemplate> rabbitTemplates) {
return new SpringwolfAmqpProducer(asyncApiService, rabbitTemplates);
}

@Bean
@ConditionalOnMissingBean
public SpringwolfAmqpController springwolfAmqpController(
AsyncApiDocketService asyncApiDocketService,
SpringwolfAmqpProducer springwolfAmqpProducer,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.Exchange;
import org.springframework.amqp.core.Queue;
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 Down Expand Up @@ -59,12 +60,14 @@ public MethodLevelRabbitListenerScanner methodLevelRabbitListenerScanner(

@Bean
@Order(value = BindingProcessorPriority.PROTOCOL_BINDING)
@ConditionalOnMissingBean
public AmqpMessageBindingProcessor amqpMessageBindingProcessor() {
return new AmqpMessageBindingProcessor();
}

@Bean
@Order(value = BindingProcessorPriority.PROTOCOL_BINDING)
@ConditionalOnMissingBean
public AmqpOperationBindingProcessor amqpOperationBindingProcessor() {
return new AmqpOperationBindingProcessor();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import io.github.stavshamir.springwolf.configuration.properties.SpringwolfKafkaConfigProperties;
import io.github.stavshamir.springwolf.producer.SpringwolfKafkaProducer;
import io.github.stavshamir.springwolf.producer.SpringwolfKafkaTemplateFactory;
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 @@ -22,6 +23,7 @@
public class SpringwolfKafkaProducerConfiguration {

@Bean
@ConditionalOnMissingBean
public SpringwolfKafkaController springwolfKafkaController(
AsyncApiDocketService asyncApiDocketService,
SpringwolfKafkaProducer springwolfKafkaProducer,
Expand All @@ -30,11 +32,13 @@ public SpringwolfKafkaController springwolfKafkaController(
}

@Bean
@ConditionalOnMissingBean
public SpringwolfKafkaProducer springwolfKafkaProducer(SpringwolfKafkaTemplateFactory producerTemplateFactory) {
return new SpringwolfKafkaProducer(producerTemplateFactory.buildKafkaTemplate());
}

@Bean
@ConditionalOnMissingBean
public SpringwolfKafkaTemplateFactory springwolfKafkaTemplateFactory(
SpringwolfKafkaConfigProperties springwolfKafkaConfigProperties) {
return new SpringwolfKafkaTemplateFactory(springwolfKafkaConfigProperties);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import io.github.stavshamir.springwolf.asyncapi.scanners.channels.annotation.MethodLevelKafkaListenerScanner;
import io.github.stavshamir.springwolf.asyncapi.scanners.classes.ComponentClassScanner;
import io.github.stavshamir.springwolf.schemas.SchemasService;
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 Down Expand Up @@ -46,12 +47,14 @@ public MethodLevelKafkaListenerScanner methodLevelKafkaListenerScanner(

@Bean
@Order(value = BindingProcessorPriority.PROTOCOL_BINDING)
@ConditionalOnMissingBean
public KafkaMessageBindingProcessor kafkaMessageBindingProcessor() {
return new KafkaMessageBindingProcessor();
}

@Bean
@Order(value = BindingProcessorPriority.PROTOCOL_BINDING)
@ConditionalOnMissingBean
public KafkaOperationBindingProcessor kafkaOperationBindingProcessor() {
return new KafkaOperationBindingProcessor();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import io.github.stavshamir.springwolf.asyncapi.controller.SpringwolfSnsController;
import io.github.stavshamir.springwolf.configuration.AsyncApiDocketService;
import io.github.stavshamir.springwolf.producer.SpringwolfSnsProducer;
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 @@ -23,6 +24,7 @@
public class SpringwolfSnsProducerConfiguration {

@Bean
@ConditionalOnMissingBean
public SpringwolfSnsController springwolfSnsController(
AsyncApiDocketService asyncApiDocketService,
SpringwolfSnsProducer springwolfSnsProducer,
Expand All @@ -31,6 +33,7 @@ public SpringwolfSnsController springwolfSnsController(
}

@Bean
@ConditionalOnMissingBean
public SpringwolfSnsProducer springwolfSnsProducer(List<SnsTemplate> snsTemplate) {
return new SpringwolfSnsProducer(snsTemplate);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import io.github.stavshamir.springwolf.asyncapi.scanners.bindings.BindingProcessorPriority;
import io.github.stavshamir.springwolf.asyncapi.scanners.channels.operationdata.SnsMessageBindingProcessor;
import io.github.stavshamir.springwolf.asyncapi.scanners.channels.operationdata.SnsOperationBindingProcessor;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.annotation.Order;
Expand All @@ -16,12 +17,14 @@ public class SpringwolfSnsScannerConfiguration {

@Bean
@Order(value = BindingProcessorPriority.PROTOCOL_BINDING)
@ConditionalOnMissingBean
public SnsMessageBindingProcessor snsMessageBindingProcessor() {
return new SnsMessageBindingProcessor();
}

@Bean
@Order(value = BindingProcessorPriority.PROTOCOL_BINDING)
@ConditionalOnMissingBean
public SnsOperationBindingProcessor snsOperationBindingProcessor() {
return new SnsOperationBindingProcessor();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import io.github.stavshamir.springwolf.asyncapi.controller.SpringwolfSqsController;
import io.github.stavshamir.springwolf.configuration.AsyncApiDocketService;
import io.github.stavshamir.springwolf.producer.SpringwolfSqsProducer;
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 @@ -23,11 +24,13 @@
public class SpringwolfSqsProducerConfiguration {

@Bean
@ConditionalOnMissingBean
public SpringwolfSqsProducer springwolfSqsProducer(List<SqsTemplate> sqsTemplates) {
return new SpringwolfSqsProducer(sqsTemplates);
}

@Bean
@ConditionalOnMissingBean
public SpringwolfSqsController springwolfSqsController(
AsyncApiDocketService asyncApiDocketService,
SpringwolfSqsProducer springwolfSqsProducer,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import io.github.stavshamir.springwolf.asyncapi.scanners.channels.annotation.MethodLevelSqsListenerScanner;
import io.github.stavshamir.springwolf.asyncapi.scanners.classes.ComponentClassScanner;
import io.github.stavshamir.springwolf.schemas.SchemasService;
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 @@ -31,12 +32,14 @@ public MethodLevelSqsListenerScanner methodLevelSqsListenerScanner(

@Bean
@Order(value = BindingProcessorPriority.PROTOCOL_BINDING)
@ConditionalOnMissingBean
public SqsMessageBindingProcessor sqsMessageBindingProcessor() {
return new SqsMessageBindingProcessor();
}

@Bean
@Order(value = BindingProcessorPriority.PROTOCOL_BINDING)
@ConditionalOnMissingBean
public SqsOperationBindingProcessor sqsOperationBindingProcessor() {
return new SqsOperationBindingProcessor();
}
Expand Down

0 comments on commit d76ecb1

Please sign in to comment.