-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature/replace componentscan (#386)
* # 291 replace componentscan based context configuration with explicit configuration file and @beans declarations * #291 replace explicit constructors with lombok annotation. * #291 @conditional on springwolf.enabled for all autoconfigurations. * #291 spotless format * chore(kafka): move SpringwolfKafkaTemplateFactoryTest to producer package * refactor(core): remove unused `@Component` and `@Service` annotation As suggested in the PR Co-authored-by: sam0r040 <[email protected]> * #291 moved @order annotataions from bean classes to spring configurations --------- Co-authored-by: Timon Back <[email protected]> Co-authored-by: sam0r040 <[email protected]>
- Loading branch information
1 parent
65b49bd
commit c23bcf0
Showing
78 changed files
with
723 additions
and
365 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
...esources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
io.github.stavshamir.springwolf.common_converters.configuration.CommonModelConvertersAutoConfiguration |
86 changes: 69 additions & 17 deletions
86
...gwolf-core/src/main/java/io/github/stavshamir/springwolf/SpringwolfAutoConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,81 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
package io.github.stavshamir.springwolf; | ||
|
||
import io.github.stavshamir.springwolf.asyncapi.AsyncApiCustomizer; | ||
import io.github.stavshamir.springwolf.asyncapi.AsyncApiService; | ||
import io.github.stavshamir.springwolf.asyncapi.ChannelsService; | ||
import io.github.stavshamir.springwolf.asyncapi.DefaultAsyncApiService; | ||
import io.github.stavshamir.springwolf.asyncapi.DefaultChannelsService; | ||
import io.github.stavshamir.springwolf.asyncapi.SpringwolfInitApplicationListener; | ||
import io.github.stavshamir.springwolf.asyncapi.scanners.channels.ChannelsScanner; | ||
import io.github.stavshamir.springwolf.configuration.AsyncApiDocket; | ||
import io.github.stavshamir.springwolf.configuration.AsyncApiDocketService; | ||
import io.github.stavshamir.springwolf.configuration.DefaultAsyncApiDocketService; | ||
import io.github.stavshamir.springwolf.configuration.properties.SpringwolfConfigConstants; | ||
import io.github.stavshamir.springwolf.configuration.properties.SpringwolfConfigProperties; | ||
import io.github.stavshamir.springwolf.schemas.DefaultSchemasService; | ||
import io.github.stavshamir.springwolf.schemas.SchemasService; | ||
import io.github.stavshamir.springwolf.schemas.example.ExampleGenerator; | ||
import io.github.stavshamir.springwolf.schemas.example.ExampleJsonGenerator; | ||
import io.swagger.v3.core.converter.ModelConverter; | ||
import org.springframework.boot.autoconfigure.AutoConfiguration; | ||
import org.springframework.boot.autoconfigure.AutoConfigurationExcludeFilter; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; | ||
import org.springframework.boot.context.TypeExcludeFilter; | ||
import org.springframework.context.annotation.ComponentScan; | ||
import org.springframework.context.annotation.FilterType; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Import; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
/** | ||
* Spring Boot auto-configuration which loads all spring-beans for springwolf core and eventually loaded plugins. | ||
* <p> | ||
* This configuration uses the spring @{@link ComponentScan} mechanism to detect and load the necessary beans. Both | ||
* the core components as well as all plugin components are located underneath the base package 'io.github.stavshamir.springwolf' | ||
* so existing springwolf plugins are automatically loaded together with the springwolf core beans. | ||
* Spring Boot auto-configuration which loads all spring-beans for springwolf core module. | ||
* <p> | ||
* To disable this auto-configuration, set the environment property {@code springwolf.enabled=false}. | ||
* To disable springwolf support, set the environment property {@code springwolf.enabled=false}. | ||
*/ | ||
@AutoConfiguration | ||
@ComponentScan( | ||
basePackages = {"io.github.stavshamir.springwolf"}, | ||
excludeFilters = { | ||
@ComponentScan.Filter(type = FilterType.CUSTOM, classes = TypeExcludeFilter.class), | ||
@ComponentScan.Filter(type = FilterType.CUSTOM, classes = AutoConfigurationExcludeFilter.class) | ||
}) | ||
@Import({SpringwolfWebConfiguration.class, SpringwolfScannerConfiguration.class}) | ||
@ConditionalOnProperty(name = SpringwolfConfigConstants.SPRINGWOLF_ENABLED, matchIfMissing = true) | ||
public class SpringwolfAutoConfiguration {} | ||
public class SpringwolfAutoConfiguration { | ||
|
||
@Bean | ||
public SpringwolfConfigProperties springwolfConfigProperties() { | ||
return new SpringwolfConfigProperties(); | ||
} | ||
|
||
@Bean | ||
public SpringwolfInitApplicationListener springwolfInitApplicationListener( | ||
AsyncApiService asyncApiService, SpringwolfConfigProperties configProperties) { | ||
return new SpringwolfInitApplicationListener(asyncApiService, configProperties); | ||
} | ||
|
||
@Bean | ||
public AsyncApiService asyncApiService( | ||
AsyncApiDocketService asyncApiDocketService, | ||
ChannelsService channelsService, | ||
SchemasService schemasService, | ||
List<AsyncApiCustomizer> customizers) { | ||
return new DefaultAsyncApiService(asyncApiDocketService, channelsService, schemasService, customizers); | ||
} | ||
|
||
@Bean | ||
public ChannelsService channelsService(List<? extends ChannelsScanner> channelsScanners) { | ||
return new DefaultChannelsService(channelsScanners); | ||
} | ||
|
||
@Bean | ||
public SchemasService schemasService(List<ModelConverter> modelConverters, ExampleGenerator exampleGenerator) { | ||
return new DefaultSchemasService(modelConverters, exampleGenerator); | ||
} | ||
|
||
@Bean | ||
public AsyncApiDocketService asyncApiDocketService( | ||
Optional<AsyncApiDocket> optionalAsyncApiDocket, SpringwolfConfigProperties springwolfConfigProperties) { | ||
return new DefaultAsyncApiDocketService(optionalAsyncApiDocket, springwolfConfigProperties); | ||
} | ||
|
||
@Bean | ||
@ConditionalOnMissingBean | ||
public ExampleGenerator exampleGenerator() { | ||
return new ExampleJsonGenerator(); | ||
} | ||
} |
92 changes: 92 additions & 0 deletions
92
...lf-core/src/main/java/io/github/stavshamir/springwolf/SpringwolfScannerConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
package io.github.stavshamir.springwolf; | ||
|
||
import io.github.stavshamir.springwolf.asyncapi.scanners.beans.BeanMethodsScanner; | ||
import io.github.stavshamir.springwolf.asyncapi.scanners.beans.DefaultBeanMethodsScanner; | ||
import io.github.stavshamir.springwolf.asyncapi.scanners.channels.ChannelPriority; | ||
import io.github.stavshamir.springwolf.asyncapi.scanners.channels.operationdata.ConsumerOperationDataScanner; | ||
import io.github.stavshamir.springwolf.asyncapi.scanners.channels.operationdata.ProducerOperationDataScanner; | ||
import io.github.stavshamir.springwolf.asyncapi.scanners.channels.operationdata.annotation.AsyncListenerAnnotationScanner; | ||
import io.github.stavshamir.springwolf.asyncapi.scanners.channels.operationdata.annotation.AsyncPublisherAnnotationScanner; | ||
import io.github.stavshamir.springwolf.asyncapi.scanners.channels.operationdata.annotation.MessageBindingProcessor; | ||
import io.github.stavshamir.springwolf.asyncapi.scanners.channels.operationdata.annotation.OperationBindingProcessor; | ||
import io.github.stavshamir.springwolf.asyncapi.scanners.classes.ComponentClassScanner; | ||
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.ConditionalOnProperty; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.core.annotation.Order; | ||
import org.springframework.core.env.Environment; | ||
|
||
import java.util.List; | ||
|
||
import static io.github.stavshamir.springwolf.configuration.properties.SpringwolfConfigConstants.SPRINGWOLF_SCANNER_ASYNC_LISTENER_ENABLED; | ||
import static io.github.stavshamir.springwolf.configuration.properties.SpringwolfConfigConstants.SPRINGWOLF_SCANNER_ASYNC_PUBLISHER_ENABLED; | ||
import static io.github.stavshamir.springwolf.configuration.properties.SpringwolfConfigConstants.SPRINGWOLF_SCANNER_CONSUMER_DATA_ENABLED; | ||
import static io.github.stavshamir.springwolf.configuration.properties.SpringwolfConfigConstants.SPRINGWOLF_SCANNER_PRODUCER_DATA_ENABLED; | ||
|
||
/** | ||
* Spring configuration defining the core scanner beans. | ||
*/ | ||
@Configuration(proxyBeanMethods = false) | ||
public class SpringwolfScannerConfiguration { | ||
|
||
@Bean | ||
public ComponentClassScanner componentClassScanner( | ||
AsyncApiDocketService asyncApiDocketService, Environment environment) { | ||
return new ComponentClassScanner(asyncApiDocketService, environment); | ||
} | ||
|
||
@Bean | ||
public ConfigurationClassScanner configurationClassScanner( | ||
AsyncApiDocketService asyncApiDocketService, Environment environment) { | ||
return new ConfigurationClassScanner(asyncApiDocketService, environment); | ||
} | ||
|
||
@Bean | ||
public BeanMethodsScanner beanMethodsScanner(ConfigurationClassScanner configurationClassScanner) { | ||
return new DefaultBeanMethodsScanner(configurationClassScanner); | ||
} | ||
|
||
@Bean | ||
@ConditionalOnProperty(name = SPRINGWOLF_SCANNER_CONSUMER_DATA_ENABLED, matchIfMissing = true) | ||
@Order(value = ChannelPriority.MANUAL_DEFINED) | ||
public ConsumerOperationDataScanner consumerOperationDataScanner( | ||
AsyncApiDocketService asyncApiDocketService, SchemasService schemasService) { | ||
return new ConsumerOperationDataScanner(asyncApiDocketService, schemasService); | ||
} | ||
|
||
@Bean | ||
@ConditionalOnProperty(name = SPRINGWOLF_SCANNER_PRODUCER_DATA_ENABLED, matchIfMissing = true) | ||
@Order(value = ChannelPriority.MANUAL_DEFINED) | ||
public ProducerOperationDataScanner producerOperationDataScanner( | ||
AsyncApiDocketService asyncApiDocketService, SchemasService schemasService) { | ||
return new ProducerOperationDataScanner(asyncApiDocketService, schemasService); | ||
} | ||
|
||
@Bean | ||
@ConditionalOnProperty(name = SPRINGWOLF_SCANNER_ASYNC_LISTENER_ENABLED, matchIfMissing = true) | ||
@Order(value = ChannelPriority.ASYNC_ANNOTATION) | ||
public AsyncListenerAnnotationScanner asyncListenerAnnotationScanner( | ||
ComponentClassScanner componentClassScanner, | ||
SchemasService schemasService, | ||
List<OperationBindingProcessor> operationBindingProcessors, | ||
List<MessageBindingProcessor> messageBindingProcessors) { | ||
return new AsyncListenerAnnotationScanner( | ||
componentClassScanner, schemasService, operationBindingProcessors, messageBindingProcessors); | ||
} | ||
|
||
@Bean | ||
@ConditionalOnProperty(name = SPRINGWOLF_SCANNER_ASYNC_PUBLISHER_ENABLED, matchIfMissing = true) | ||
@Order(value = ChannelPriority.ASYNC_ANNOTATION) | ||
public AsyncPublisherAnnotationScanner asyncPublisherAnnotationScanner( | ||
ComponentClassScanner componentClassScanner, | ||
SchemasService schemasService, | ||
List<OperationBindingProcessor> operationBindingProcessors, | ||
List<MessageBindingProcessor> messageBindingProcessors) { | ||
return new AsyncPublisherAnnotationScanner( | ||
componentClassScanner, schemasService, operationBindingProcessors, messageBindingProcessors); | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
...ngwolf-core/src/main/java/io/github/stavshamir/springwolf/SpringwolfWebConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
package io.github.stavshamir.springwolf; | ||
|
||
import io.github.stavshamir.springwolf.asyncapi.AsyncApiSerializerService; | ||
import io.github.stavshamir.springwolf.asyncapi.AsyncApiService; | ||
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.ConditionalOnProperty; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
import static io.github.stavshamir.springwolf.configuration.properties.SpringwolfConfigConstants.SPRINGWOLF_ENDPOINT_ACTUATOR_ENABLED; | ||
|
||
/** | ||
* Spring-Configuration defining the web controller beans. | ||
*/ | ||
@Configuration(proxyBeanMethods = false) | ||
public class SpringwolfWebConfiguration { | ||
|
||
@Bean | ||
@ConditionalOnProperty(name = SPRINGWOLF_ENDPOINT_ACTUATOR_ENABLED, havingValue = "false", matchIfMissing = true) | ||
public AsyncApiController asyncApiController( | ||
AsyncApiService asyncApiService, AsyncApiSerializerService asyncApiSerializerService) { | ||
return new AsyncApiController(asyncApiService, asyncApiSerializerService); | ||
} | ||
|
||
@Bean | ||
@ConditionalOnProperty(name = SPRINGWOLF_ENDPOINT_ACTUATOR_ENABLED, havingValue = "true") | ||
public ActuatorAsyncApiController actuatorAsyncApiController( | ||
AsyncApiService asyncApiService, AsyncApiSerializerService asyncApiSerializerService) { | ||
return new ActuatorAsyncApiController(asyncApiService, asyncApiSerializerService); | ||
} | ||
|
||
@Bean | ||
public AsyncApiSerializerService asyncApiSerializerService() { | ||
return new DefaultAsyncApiSerializerService(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.