Class SpringComponentRegistry
- All Implemented Interfaces:
ComponentRegistry,DescribableComponent,org.springframework.beans.factory.config.BeanFactoryPostProcessor,org.springframework.beans.factory.config.BeanPostProcessor
ComponentRegistry implementation that connects into Spring's ecosystem by means of being a
BeanPostProcessor, BeanFactoryPostProcessor, and InitializingBean.
By being a BeanPostProcessor, this ComponentRegistry can decorate any Spring bean that matches with
decorators set in this ComponentRegistry or any ConfigurationEnhancer.
By being a BeanFactoryPostProcessor, this ComponentRegistry can return any component, regardless of
whether it was registered with this ComponentRegistry, through a ConfigurationEnhancer, or comes from
Spring's Application Context directly. The latter integration ensures that any Axon Framework component using
the Configuration resulting from this ComponentRegistry can retrieve any bean that's
available. The BeanFactory that's set through
BeanFactoryPostProcessor.postProcessBeanFactory(ConfigurableListableBeanFactory) is also used to
validate if this registery has a certain component.
- Since:
- 4.6.0
- Author:
- Allard Buijze, Steven van Beelen
-
Constructor Summary
ConstructorsConstructorDescriptionSpringComponentRegistry(org.springframework.beans.factory.ListableBeanFactory listableBeanFactory, SpringLifecycleRegistry lifecycleRegistry) Constructs aSpringComponentRegistrywith the givenlistableBeanFactory. -
Method Summary
Modifier and TypeMethodDescriptionAccessor method for theSpringAxonApplicationto access this registry'sConfiguration.voiddescribeTo(ComponentDescriptor descriptor) Describe the properties ofthis DescribableComponentwith the givendescriptor.disableEnhancer(Class<? extends ConfigurationEnhancer> enhancerClass) Disables the givenConfigurationEnhancerclass from executing during the configuration initialization phase.disableEnhancer(String fullyQualifiedClassName) Disables the givenConfigurationEnhancerclass from executing during the configuration initialization phase.Completely disables scanning for enhancers on the classpath through theServiceLoadermechanism.booleanhasComponent(Class<?> type, String name, SearchScope searchScope) Check whether there is aComponentregistered with thisConfigurerfor the giventypeandnamecombination.postProcessAfterInitialization(Object bean, String beanName) Override from theBeanPostProcessorinterface.voidpostProcessBeanFactory(org.springframework.beans.factory.config.ConfigurableListableBeanFactory beanFactory) registerComponent(ComponentDefinition<? extends C> definition) Registers aComponentbased on the givendefinition.registerDecorator(DecoratorDefinition<C, ? extends C> definition) Registers a decorator based on the givendefinition.registerEnhancer(ConfigurationEnhancer enhancer) Registers anConfigurationEnhancerwith thisComponentRegistry.registerFactory(ComponentFactory<C> factory) Registers aComponentFactorywith this registry.registerModule(Module module) Registers aModulewith this registry.setOverridePolicy(OverridePolicy overridePolicy) Sets theOverridePolicyfor thisComponentRegistry.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.springframework.beans.factory.config.BeanPostProcessor
postProcessBeforeInitializationMethods inherited from interface org.axonframework.common.configuration.ComponentRegistry
hasComponent, hasComponent, hasComponent, registerComponent, registerComponent, registerDecorator, registerDecorator, registerIfNotPresent, registerIfNotPresent, registerIfNotPresent, registerIfNotPresent, registerIfNotPresent, registerIfNotPresent
-
Constructor Details
-
SpringComponentRegistry
@Internal public SpringComponentRegistry(@Nonnull org.springframework.beans.factory.ListableBeanFactory listableBeanFactory, @Nonnull SpringLifecycleRegistry lifecycleRegistry) Constructs aSpringComponentRegistrywith the givenlistableBeanFactory. ThelistableBeanFactoryis used to discover all beans of typeConfigurationEnhancer.- Parameters:
listableBeanFactory- The bean factory used to discover all beans of typeConfigurationEnhancer.lifecycleRegistry- TheLifecycleRegistryused to initializesregistered modules.
-
-
Method Details
-
registerComponent
public <C> ComponentRegistry registerComponent(@Nonnull ComponentDefinition<? extends C> definition) Description copied from interface:ComponentRegistryRegisters aComponentbased on the givendefinition.- Specified by:
registerComponentin interfaceComponentRegistry- Type Parameters:
C- The declared type of the component.- Parameters:
definition- The definition of the component to register.- Returns:
- The current instance of the
Configurerfor a fluent API.
-
registerDecorator
public <C> ComponentRegistry registerDecorator(@Nonnull DecoratorDefinition<C, ? extends C> definition) Description copied from interface:ComponentRegistryRegisters a decorator based on the givendefinition.- Specified by:
registerDecoratorin interfaceComponentRegistry- Type Parameters:
C- The declared type of the component(s) to decorate.- Parameters:
definition- The definition of the decorator to apply to components.- Returns:
- The current instance of the
Configurerfor a fluent API. - See Also:
-
hasComponent
public boolean hasComponent(@Nonnull Class<?> type, @Nullable String name, @Nonnull SearchScope searchScope) Description copied from interface:ComponentRegistryCheck whether there is aComponentregistered with thisConfigurerfor the giventypeandnamecombination.The given
searchScopeis used to define if the search only checks thecurrentregistry, only checks allancestors, or checksboththe current registry and all ancestors.- Specified by:
hasComponentin interfaceComponentRegistry- Parameters:
type- The type of theComponentto check if it exists, typically an interface.name- The name of theComponentto check if it exists. Usenullwhen there is no name or useComponentRegistry.hasComponent(Class)instead.searchScope- The enumeration defining the search scope used to check if this registry has aComponent.- Returns:
truewhen there is aComponentregistered under the giventypeandname combination,falseotherwise.
-
registerEnhancer
Description copied from interface:ComponentRegistryRegisters anConfigurationEnhancerwith thisComponentRegistry.An
enhanceris able to invoke any of the methods on thisComponentRegistry, allowing it to add (sensible) defaults, decoratecomponents, or replace components entirely.An enhancer's
ConfigurationEnhancer.enhance(ComponentRegistry)method is invoked during the initialization phase when all components have been defined. This is right before theComponentRegistrycreates itsConfiguration.When multiple enhancers have been provided, their
ConfigurationEnhancer.order()dictates the enhancement order. For enhancer with the same order, the order of execution is undefined.- Specified by:
registerEnhancerin interfaceComponentRegistry- Parameters:
enhancer- The configuration enhancer to enhance ComponentRegistry duringApplicationConfigurer.build().- Returns:
- The current instance of the
Configurerfor a fluent API.
-
registerModule
Description copied from interface:ComponentRegistryRegisters aModulewith this registry.Note that a
Moduleis able to access the components defined in thisComponentRegistryupon construction, but not vice versa. As such, theModulemaintains encapsulation.- Specified by:
registerModulein interfaceComponentRegistry- Parameters:
module- The module builder function to register.- Returns:
- The current instance of the
ComponentRegistryfor a fluent API.
-
registerFactory
Description copied from interface:ComponentRegistryRegisters aComponentFactorywith this registry.If the
Configurationthat will contain this registry does not have a component for a givenClassand name combination, it will consult all registered component factories. Only if a givenfactorycan produce therequested typewillComponentFactory.construct(String, Configuration)be invoked. When thefactorydecides to construct a new component, it will be stored in theConfigurationfor future reference to ensure it's not constructed again.- Specified by:
registerFactoryin interfaceComponentRegistry- Type Parameters:
C- The component type constructed by the givenfactory.- Parameters:
factory- The component factory to register.- Returns:
- The current instance of the
ComponentRegistryfor a fluent API.
-
setOverridePolicy
Description copied from interface:ComponentRegistrySets theOverridePolicyfor thisComponentRegistry.This policy dictates what should happen when components are registered with an identifier for which another component is already present.
- Specified by:
setOverridePolicyin interfaceComponentRegistry- Parameters:
overridePolicy- The override policy for components defined in this registry.- Returns:
- The current instance of the
Configurerfor a fluent API.
-
disableEnhancerScanning
Description copied from interface:ComponentRegistryCompletely disables scanning for enhancers on the classpath through theServiceLoadermechanism. Note that this may lead to missing framework functionality. It is recommended to disable specific enhancers throughComponentRegistry.disableEnhancer(Class)instead. Does not affect enhancers that are registered through theComponentRegistry.registerEnhancer(ConfigurationEnhancer)method.- Specified by:
disableEnhancerScanningin interfaceComponentRegistry- Returns:
- The current instance of the
Configurerfor a fluent API.
-
disableEnhancer
Description copied from interface:ComponentRegistryDisables the givenConfigurationEnhancerclass from executing during the configuration initialization phase. This affects both enhancers registered through theServiceLoadermechanism and those registered programmatically viaComponentRegistry.registerEnhancer(ConfigurationEnhancer).Only specific classes can be disabled, and class hierarchies are not taken into account. If the enhancer has already been invoked when this method is called, disabling will have no effect and a warning will be logged.
This method is typically called from within another enhancer's
ConfigurationEnhancer.enhance(ComponentRegistry)method to prevent subsequent enhancers from executing.If the class cannot be found on the classpath, a warning will be logged and the call will have no effect.
- Specified by:
disableEnhancerin interfaceComponentRegistry- Parameters:
fullyQualifiedClassName- The fully qualified class name of the enhancer to disable.- Returns:
- The current instance of the
Configurerfor a fluent API.
-
disableEnhancer
Description copied from interface:ComponentRegistryDisables the givenConfigurationEnhancerclass from executing during the configuration initialization phase. This affects both enhancers registered through theServiceLoadermechanism and those registered programmatically viaComponentRegistry.registerEnhancer(ConfigurationEnhancer).Only specific classes can be disabled, and class hierarchies are not taken into account. If the enhancer has already been invoked when this method is called, disabling will have no effect and a warning will be logged.
This method is typically called from within another enhancer's
ConfigurationEnhancer.enhance(ComponentRegistry)method to prevent subsequent enhancers from executing.- Specified by:
disableEnhancerin interfaceComponentRegistry- Parameters:
enhancerClass- The class of the enhancer to disable.- Returns:
- The current instance of the
Configurerfor a fluent API.
-
describeTo
Description copied from interface:DescribableComponentDescribe the properties ofthis DescribableComponentwith the givendescriptor.Components should call the appropriate
describePropertymethods on the descriptor to register their properties. The descriptor is responsible for determining how these properties are formatted and structured in the final output.Best Practices: As a general rule, all relevant fields of a
DescribableComponentimplementation should be described in this method. However, developers have discretion to include only the fields that make sense in the context. Not every field may be meaningful for description purposes, especially internal implementation details. Furthermore, components might want to expose different information based on their current state. The final decision on what properties to include lies with the person implementing thedescribeTomethod, who should focus on providing information that is useful for understanding the component's configuration and state.Example implementation:
public void describeTo(ComponentDescriptor descriptor) { descriptor.describeProperty("name", this.name); descriptor.describeProperty("enabled", this.enabled); descriptor.describeProperty("configuration", this.configuration); // A nested component descriptor.describeProperty("handlers", this.eventHandlers); // A collection }- Specified by:
describeToin interfaceDescribableComponent- Parameters:
descriptor- The component descriptor to describethis DescribableComponentn its properties in.
-
postProcessBeanFactory
public void postProcessBeanFactory(@Nonnull org.springframework.beans.factory.config.ConfigurableListableBeanFactory beanFactory) throws org.springframework.beans.BeansException - Specified by:
postProcessBeanFactoryin interfaceorg.springframework.beans.factory.config.BeanFactoryPostProcessor- Throws:
org.springframework.beans.BeansException
-
postProcessAfterInitialization
public Object postProcessAfterInitialization(@Nonnull Object bean, @Nonnull String beanName) throws org.springframework.beans.BeansException Override from theBeanPostProcessorinterface.This ensures that
registered decoratorsor decorators registered throughConfigurationEnhancersare invoked for Spring beans that match Axon's type-and-name criteria for decoration.Will retrieve a
ResolvableTypefrom the givenbeanNamefrom theConfigurableListableBeanFactoryset throughpostProcessBeanFactory(ConfigurableListableBeanFactory)(if contained in said bean factory). Doing so ensures we match decorators with the bean's registered type instead of the bean's concrete type.Generic type checks on the
DecoratorDefinitionand it's invocations are suppressed as we're dealing with wildcards. Furthermore, theDecoratorDefinition.CompletedDecoratorDefinition.matches(Component.Identifier)invocation ensures we validate if theDecoratorDefinition.CompletedDecoratorDefinition.decorate(Component)invocations is valid.- Specified by:
postProcessAfterInitializationin interfaceorg.springframework.beans.factory.config.BeanPostProcessor- Throws:
org.springframework.beans.BeansException
-
configuration
Accessor method for theSpringAxonApplicationto access this registry'sConfiguration.- Returns:
- The
Configurationconstructed by thisComponentRegistry.
-