Interface ApplicationEventInterceptor
-
- All Superinterfaces:
org.springframework.core.Ordered
public interface ApplicationEventInterceptor extends org.springframework.core.Ordered
An interface used to interceptapplication events
allowing for pre-processing, post-processing, or even prevention of event propagation through theinterceptor chain
.Interceptors can be used to implement cross-cutting concerns such as logging, security checks, or performance monitoring around the application event handling process.
Example Usage
{@code public class LoggingInterceptor implements ApplicationEventInterceptor {
- Since:
- 1.0.0
- Author:
- Mercy
- See Also:
ApplicationEvent
,ApplicationEventInterceptorChain
,Ordered
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default int
getOrder()
void
intercept(org.springframework.context.ApplicationEvent event, org.springframework.core.ResolvableType eventType, ApplicationEventInterceptorChain chain)
Intercept the specifiedApplicationEvent
with its resolved type, allowing custom pre-processing, post-processing, or short-circuiting the event propagation by not invoking the next interceptor in the chain.
-
-
-
Method Detail
-
intercept
void intercept(org.springframework.context.ApplicationEvent event, org.springframework.core.ResolvableType eventType, ApplicationEventInterceptorChain chain)
Intercept the specifiedApplicationEvent
with its resolved type, allowing custom pre-processing, post-processing, or short-circuiting the event propagation by not invoking the next interceptor in the chain.Example Usage
Implementing a simple logging interceptor:
Short-circuiting: To prevent further processing of an event, simply skip callingpublic class SampleInterceptor implements ApplicationEventInterceptor { public void intercept(ApplicationEvent event, ResolvableType eventType, ApplicationEventInterceptorChain chain) { System.out.println("Intercepting event: " + event); // Proceed to the next interceptor in the chain chain.intercept(event, eventType); System.out.println("Finished handling event: " + event); } }
ApplicationEventInterceptorChain.intercept(ApplicationEvent, ResolvableType)
:public class SilentEventInterceptor implements ApplicationEventInterceptor { public void intercept(ApplicationEvent event, ResolvableType eventType, ApplicationEventInterceptorChain chain) { // Skip calling chain.proceed() to prevent event propagation System.out.println("Event blocked: " + event); } }
- Parameters:
event
- the event being intercepted; nevernull
eventType
- the resolved type of the event, useful for filtering or conditional logicchain
- the interceptor chain to continue processing if desired
-
getOrder
default int getOrder()
- Specified by:
getOrder
in interfaceorg.springframework.core.Ordered
-
-