Class SpringPrototypeAggregateFactory<T>
- Type Parameters:
T- The type of aggregate generated by this aggregate factory.
- All Implemented Interfaces:
org.axonframework.eventsourcing.AggregateFactory<T>,org.springframework.beans.factory.Aware,org.springframework.beans.factory.BeanNameAware,org.springframework.beans.factory.InitializingBean,org.springframework.context.ApplicationContextAware
AggregateFactory implementation that uses Spring prototype beans to create new uninitialized instances of
Aggregates.- Since:
- 1.2
- Author:
- Allard Buijze
-
Constructor Summary
ConstructorsConstructorDescriptionSpringPrototypeAggregateFactory(Class<T> aggregateType, String prototypeBeanName, Map<Class<? extends T>, String> subtypes) Initializes the factory to create bean instances from the givenprototypeBeanNameor itssubtypes.SpringPrototypeAggregateFactory(String prototypeBeanName) Deprecated.Deprecated.In favor ofSpringPrototypeAggregateFactory(Class, String, Map)to ensure all required fields are present for both polymorphic and non-polymorphic aggregates. -
Method Summary
Modifier and TypeMethodDescriptionvoidcreateAggregateRoot(String aggregateIdentifier, org.axonframework.eventhandling.DomainEventMessage<?> firstEvent) voidsetApplicationContext(org.springframework.context.ApplicationContext applicationContext) voidsetBeanName(String beanName) static <T> SpringPrototypeAggregateFactory<T>withSubtypeSupport(Class<T> aggregateType, String prototypeBeanName, Map<Class<? extends T>, String> subtypes) Initializes the factory to create bean instances from the givenprototypeBeanNameor itssubtypes.
-
Constructor Details
-
SpringPrototypeAggregateFactory
Deprecated.In favor ofSpringPrototypeAggregateFactory(Class, String, Map)to ensure all required fields are present for both polymorphic and non-polymorphic aggregates.Initializes the factory to create beans instances for the bean with givenprototypeBeanName.Note that the bean should have the prototype scope.
- Parameters:
prototypeBeanName- the name of the prototype bean this repository serves.
-
SpringPrototypeAggregateFactory
@Deprecated public SpringPrototypeAggregateFactory(String prototypeBeanName, Map<Class<? extends T>, String> subtypes) Deprecated.In favor ofSpringPrototypeAggregateFactory(Class, String, Map)to ensure all required fields are present for both polymorphic and non-polymorphic aggregates.Initializes the factory to create beans instances for the bean with givenprototypeBeanNameand itssubtypes.Note that the bean should have the prototype scope.
- Parameters:
prototypeBeanName- the name of the prototype bean this repository serves.subtypes- the map of subtype of this aggregate to its spring prototype name
-
SpringPrototypeAggregateFactory
public SpringPrototypeAggregateFactory(Class<T> aggregateType, String prototypeBeanName, Map<Class<? extends T>, String> subtypes) Initializes the factory to create bean instances from the givenprototypeBeanNameor itssubtypes.Whenever
subtypesis not null, it is expected that theprototypeBeanNamedoes not exist in theApplicationContextdue to the fact that root types are expected to beabstract. Furthermore,abstractclasses are not made a part of theApplicationContextand as such there cannot be a bean definition referencing it.Note that the
prototypeBeanNameshould have the prototype scope when there are notsubtypes. Whensubtypesare present, all values of thesubtypescollection are expected to be prototype scoped.- Parameters:
aggregateType- The type of aggregate constructed by thisAggregateFactory. Is the root type of the aggregate wheneversubtypesis not empty.prototypeBeanName- The name of the prototype bean this repository serves. Whensubtypesisn't empty, the name is expected to equal thesimple nameof theaggregateType.subtypes- The map of subtype of this aggregate to its spring prototype name. @return An initialized instance of this factory.
-
-
Method Details
-
withSubtypeSupport
public static <T> SpringPrototypeAggregateFactory<T> withSubtypeSupport(Class<T> aggregateType, String prototypeBeanName, Map<Class<? extends T>, String> subtypes) Initializes the factory to create bean instances from the givenprototypeBeanNameor itssubtypes.Whenever
subtypesis not null, it is expected that theprototypeBeanNamedoes not exist in theApplicationContextdue to the fact that root types are expected to beabstract. Furthermore,abstractclasses are not made a part of theApplicationContextand as such there cannot be a bean definition referencing it.Note that the
prototypeBeanNameshould have the prototype scope when there are notsubtypes. Whensubtypesare present, all values of thesubtypescollection are expected to be prototype scoped.This static factory method is provided as an alternative to avoid warnings and errors on ambiguous constructor resolution when using Spring AOT.
- Parameters:
aggregateType- The type of aggregate constructed by thisAggregateFactory. Is the root type of the aggregate wheneversubtypesis not empty.prototypeBeanName- The name of the prototype bean this repository serves. Whensubtypesisn't empty, the name is expected to equal thesimple nameof theaggregateType.subtypes- The map of subtype of this aggregate to its spring prototype name. @return An initialized instance of this factory.
-
createAggregateRoot
public T createAggregateRoot(String aggregateIdentifier, org.axonframework.eventhandling.DomainEventMessage<?> firstEvent) - Specified by:
createAggregateRootin interfaceorg.axonframework.eventsourcing.AggregateFactory<T>
-
getAggregateType
- Specified by:
getAggregateTypein interfaceorg.axonframework.eventsourcing.AggregateFactory<T>
-
setApplicationContext
public void setApplicationContext(@Nonnull org.springframework.context.ApplicationContext applicationContext) - Specified by:
setApplicationContextin interfaceorg.springframework.context.ApplicationContextAware
-
setBeanName
- Specified by:
setBeanNamein interfaceorg.springframework.beans.factory.BeanNameAware
-
afterPropertiesSet
public void afterPropertiesSet()- Specified by:
afterPropertiesSetin interfaceorg.springframework.beans.factory.InitializingBean
-
SpringPrototypeAggregateFactory(Class, String, Map)to ensure all required fields are present for both polymorphic and non-polymorphic aggregates.