Interface ApplicationEventInterceptor

  • All Superinterfaces:
    org.springframework.core.Ordered

    public interface ApplicationEventInterceptor
    extends org.springframework.core.Ordered
    An interface used to intercept application events allowing for pre-processing, post-processing, or even prevention of event propagation through the interceptor 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
    • Field Summary

      • Fields inherited from interface org.springframework.core.Ordered

        HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
    • 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 specified ApplicationEvent 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 specified ApplicationEvent 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:
        
         public 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);
             }
         }
         
        Short-circuiting: To prevent further processing of an event, simply skip calling 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; never null
        eventType - the resolved type of the event, useful for filtering or conditional logic
        chain - the interceptor chain to continue processing if desired
      • getOrder

        default int getOrder()
        Specified by:
        getOrder in interface org.springframework.core.Ordered