Class FluxCapacitorSpringConfig
java.lang.Object
io.fluxcapacitor.javaclient.configuration.spring.FluxCapacitorSpringConfig
- All Implemented Interfaces:
org.springframework.beans.factory.config.BeanPostProcessor
@Configuration
public class FluxCapacitorSpringConfig
extends Object
implements org.springframework.beans.factory.config.BeanPostProcessor
Spring configuration class for automatically wiring and initializing common Flux Capacitor components in a Spring
application context.
This configuration simplifies the integration of Flux Capacitor by:
- Registering
@Handle...
annotated beans as handlers after the context is refreshed - Auto-detecting and registering upcasters and downcasters with the
Serializer
- Providing default implementations for core interfaces like
CommandGateway
,Serializer
, andMessageScheduler
Note that Flux Capacitor does not require Spring, and this class is entirely optional. It exists purely to reduce boilerplate in Spring-based applications.
The simplest way to enable this configuration in a Spring Boot application, is by annotating your main application class with:
@SpringBootApplication
@Import(FluxCapacitorSpringConfig.class)
- See Also:
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
FluxCapacitorSpringConfig
(org.springframework.context.ApplicationContext context) Stores a reference to the Spring context and prepares for handler detection. -
Method Summary
Modifier and TypeMethodDescriptionaggregateRepository
(FluxCapacitor fluxCapacitor) commandGateway
(FluxCapacitor fluxCapacitor) documentStore
(FluxCapacitor fluxCapacitor) errorGateway
(FluxCapacitor fluxCapacitor) eventGateway
(FluxCapacitor fluxCapacitor) fluxCapacitor
(FluxCapacitorBuilder builder, List<FluxCapacitorCustomizer> customizers) Constructs theFluxCapacitor
instance if no FluxCapacitor bean exists, preferring a user-providedClient
or falling back to either aWebSocketClient
orLocalClient
depending on presence of configuration properties.fluxCapacitorBuilder
(Serializer serializer, Optional<UserProvider> userProvider, Optional<Cache> cache, Optional<WebResponseMapper> webResponseMapper, org.springframework.core.env.Environment environment) Provides a defaultFluxCapacitorBuilder
, configured using Spring-provided components such asUserProvider
,Cache
, andWebResponseMapper
.protected <T> Optional
<T> void
handle
(org.springframework.context.event.ContextRefreshedEvent event) Registers all discovered Spring beans as Flux Capacitor handlers once the application context is refreshed.keyValueStore
(FluxCapacitor fluxCapacitor) metricsGateway
(FluxCapacitor fluxCapacitor) postProcessAfterInitialization
(Object bean, String beanName) Captures beans post-initialization to inspect later for handler registration.queryGateway
(FluxCapacitor fluxCapacitor) resultGateway
(FluxCapacitor fluxCapacitor) scheduler
(FluxCapacitor fluxCapacitor) Optionally provides a defaultSerializer
implementation based on Jackson, automatically detecting and registering upcasters and downcasters from Spring-managed beans.static SocketEndpointPostProcessor
Registers theSocketEndpointPostProcessor
, used for handlers that manage WebSocket communication.static StatefulPostProcessor
Registers theStatefulPostProcessor
, enabling lifecycle and stateful behavior for beans.static TrackSelfPostProcessor
Registers theTrackSelfPostProcessor
, which supports payload classes that track and handle their own type.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.springframework.beans.factory.config.BeanPostProcessor
postProcessBeforeInitialization
-
Constructor Details
-
FluxCapacitorSpringConfig
@Autowired protected FluxCapacitorSpringConfig(org.springframework.context.ApplicationContext context) Stores a reference to the Spring context and prepares for handler detection.
-
-
Method Details
-
trackSelfPostProcessor
Registers theTrackSelfPostProcessor
, which supports payload classes that track and handle their own type.- See Also:
-
statefulPostProcessor
Registers theStatefulPostProcessor
, enabling lifecycle and stateful behavior for beans.- See Also:
-
socketEndpointPostProcessor
Registers theSocketEndpointPostProcessor
, used for handlers that manage WebSocket communication.- See Also:
-
postProcessAfterInitialization
public Object postProcessAfterInitialization(Object bean, String beanName) throws org.springframework.beans.BeansException Captures beans post-initialization to inspect later for handler registration. Prototype beans are handled specially.- Specified by:
postProcessAfterInitialization
in interfaceorg.springframework.beans.factory.config.BeanPostProcessor
- Throws:
org.springframework.beans.BeansException
-
handle
@EventListener public void handle(org.springframework.context.event.ContextRefreshedEvent event) Registers all discovered Spring beans as Flux Capacitor handlers once the application context is refreshed. Also installs a default uncaught exception handler and starts the application context if needed. -
serializer
Optionally provides a defaultSerializer
implementation based on Jackson, automatically detecting and registering upcasters and downcasters from Spring-managed beans.This method is only invoked if no other
Serializer
bean is defined.If a custom serializer is provided by the application, upcasters and downcasters must be registered explicitly.
- Returns:
- a
Serializer
configured with discovered casting logic
-
fluxCapacitorBuilder
@Bean public FluxCapacitorBuilder fluxCapacitorBuilder(Serializer serializer, Optional<UserProvider> userProvider, Optional<Cache> cache, Optional<WebResponseMapper> webResponseMapper, org.springframework.core.env.Environment environment) Provides a defaultFluxCapacitorBuilder
, configured using Spring-provided components such asUserProvider
,Cache
, andWebResponseMapper
. Automatically uses application properties viaSpringPropertySource
. -
fluxCapacitor
@Bean public FluxCapacitor fluxCapacitor(FluxCapacitorBuilder builder, List<FluxCapacitorCustomizer> customizers) Constructs theFluxCapacitor
instance if no FluxCapacitor bean exists, preferring a user-providedClient
or falling back to either aWebSocketClient
orLocalClient
depending on presence of configuration properties. -
aggregateRepository
-
scheduler
-
commandGateway
-
eventGateway
-
queryGateway
-
errorGateway
-
metricsGateway
-
resultGateway
-
keyValueStore
-
documentStore
-
getBean
-