Class TrackSelfPostProcessor
java.lang.Object
io.fluxzero.sdk.configuration.spring.TrackSelfPostProcessor
- All Implemented Interfaces:
org.springframework.beans.factory.Aware, org.springframework.beans.factory.config.BeanFactoryPostProcessor, org.springframework.beans.factory.support.BeanDefinitionRegistryPostProcessor, org.springframework.context.EnvironmentAware
public class TrackSelfPostProcessor
extends Object
implements org.springframework.beans.factory.support.BeanDefinitionRegistryPostProcessor, org.springframework.context.EnvironmentAware
Spring
BeanDefinitionRegistryPostProcessor that detects classes annotated with TrackSelf
and registers them as FluxzeroPrototype beans for use by Fluxzero.
This processor differs from StatefulPostProcessor in that it performs full classpath scanning—rather
than only inspecting instantiated beans—because it must also detect interfaces and abstract classes annotated
with @TrackSelf. These types represent projection definitions that are later handled dynamically.
All detected @TrackSelf types are wrapped as FluxzeroPrototype and registered as Spring bean
definitions, allowing Fluxzero to discover and register them as self-tracking projections at runtime.
Usage
To enable self-tracking on a class use e.g.:@TrackSelf
public interface UserUpdate {
UserId getUserId();
@HandleCommand
default void handle() {
Fluxzero.loadAggregate(getUserId()).assertAndApply(this);
}
}
Make sure Spring picks up this processor, for example by including
FluxzeroSpringConfig in your configuration:
@SpringBootApplication
@Import(FluxzeroSpringConfig.class)
public class MyApp { ... }
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected Class<?> extractBeanClass(org.springframework.beans.factory.config.BeanDefinition beanDefinition) Extracts the target class from the scannedBeanDefinition.voidpostProcessBeanDefinitionRegistry(@NonNull org.springframework.beans.factory.support.BeanDefinitionRegistry registry) No-op.voidpostProcessBeanFactory(@NonNull org.springframework.beans.factory.config.ConfigurableListableBeanFactory beanFactory) Scans the classpath for components annotated withTrackSelf, based onComponentScanmetadata, and registers each of them as aFluxzeroPrototype.voidsetEnvironment(org.springframework.core.env.Environment environment) Sets the SpringEnvironmentused for context-aware scanning.
-
Constructor Details
-
TrackSelfPostProcessor
public TrackSelfPostProcessor()
-
-
Method Details
-
postProcessBeanFactory
public void postProcessBeanFactory(@NonNull @NonNull org.springframework.beans.factory.config.ConfigurableListableBeanFactory beanFactory) throws org.springframework.beans.BeansException Scans the classpath for components annotated withTrackSelf, based onComponentScanmetadata, and registers each of them as aFluxzeroPrototype.If the
beanFactoryis not aBeanDefinitionRegistry, a warning is logged and processing is skipped.- Specified by:
postProcessBeanFactoryin interfaceorg.springframework.beans.factory.support.BeanDefinitionRegistryPostProcessor- Specified by:
postProcessBeanFactoryin interfaceorg.springframework.beans.factory.config.BeanFactoryPostProcessor- Throws:
org.springframework.beans.BeansException
-
extractBeanClass
protected Class<?> extractBeanClass(org.springframework.beans.factory.config.BeanDefinition beanDefinition) Extracts the target class from the scannedBeanDefinition.- Parameters:
beanDefinition- the scanned bean definition- Returns:
- the resolved class, or
nullif not resolvable
-
postProcessBeanDefinitionRegistry
public void postProcessBeanDefinitionRegistry(@NonNull @NonNull org.springframework.beans.factory.support.BeanDefinitionRegistry registry) throws org.springframework.beans.BeansException No-op. This implementation does not modify the registry at this phase.- Specified by:
postProcessBeanDefinitionRegistryin interfaceorg.springframework.beans.factory.support.BeanDefinitionRegistryPostProcessor- Parameters:
registry- theBeanDefinitionRegistry- Throws:
org.springframework.beans.BeansException
-
setEnvironment
public void setEnvironment(org.springframework.core.env.Environment environment) Sets the SpringEnvironmentused for context-aware scanning.- Specified by:
setEnvironmentin interfaceorg.springframework.context.EnvironmentAware
-