Class EventPublicationInterceptor
- java.lang.Object
- org.springframework.context.event.EventPublicationInterceptor
- All Implemented Interfaces:
Advice,Interceptor,MethodInterceptor,Aware,InitializingBean,ApplicationEventPublisherAware
public class EventPublicationInterceptor extends Object implements MethodInterceptor, ApplicationEventPublisherAware, InitializingBean
Interceptorthat publishes anApplicationEventto allApplicationListenersregistered with anApplicationEventPublisherafter each successful method invocation.Note that this interceptor is only capable of publishing stateless events configured via the
"applicationEventClass"property.- Author:
- Dmitriy Kopylenko, Juergen Hoeller, Rick Evans
- See Also:
setApplicationEventClass(java.lang.Class<?>),ApplicationEvent,ApplicationListener,ApplicationEventPublisher,ApplicationContext
Constructor Summary
Constructors Constructor Description EventPublicationInterceptor()
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidafterPropertiesSet()Invoked by the containingBeanFactoryafter it has set all bean properties and satisfiedBeanFactoryAware,ApplicationContextAwareetc.Objectinvoke(MethodInvocation invocation)Implement this method to perform extra treatments before and after the invocation.voidsetApplicationEventClass(Class<?> applicationEventClass)Set the application event class to publish.voidsetApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher)Set the ApplicationEventPublisher that this object runs in.
Constructor Detail
EventPublicationInterceptor
public EventPublicationInterceptor()
Method Detail
setApplicationEventClass
public void setApplicationEventClass(Class<?> applicationEventClass)
Set the application event class to publish.The event class must have a constructor with a single
Objectargument for the event source. The interceptor will pass in the invoked object.- Throws:
IllegalArgumentException- if the suppliedClassisnullor if it is not anApplicationEventsubclass or if it does not expose a constructor that takes a singleObjectargument
setApplicationEventPublisher
public void setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher)
Description copied from interface:ApplicationEventPublisherAwareSet the ApplicationEventPublisher that this object runs in.Invoked after population of normal bean properties but before an init callback like InitializingBean's afterPropertiesSet or a custom init-method. Invoked before ApplicationContextAware's setApplicationContext.
- Specified by:
setApplicationEventPublisherin interfaceApplicationEventPublisherAware- Parameters:
applicationEventPublisher- event publisher to be used by this object
afterPropertiesSet
public void afterPropertiesSet() throws Exception
Description copied from interface:InitializingBeanInvoked by the containingBeanFactoryafter it has set all bean properties and satisfiedBeanFactoryAware,ApplicationContextAwareetc.This method allows the bean instance to perform validation of its overall configuration and final initialization when all bean properties have been set.
- Specified by:
afterPropertiesSetin interfaceInitializingBean- Throws:
Exception- in the event of misconfiguration (such as failure to set an essential property) or if initialization fails for any other reason
invoke
public Object invoke(MethodInvocation invocation) throws Throwable
Description copied from interface:MethodInterceptorImplement this method to perform extra treatments before and after the invocation. Polite implementations would certainly like to invokeJoinpoint.proceed().- Specified by:
invokein interfaceMethodInterceptor- Parameters:
invocation- the method invocation joinpoint- Returns:
- the result of the call to
Joinpoint.proceed(); might be intercepted by the interceptor - Throws:
Throwable- if the interceptors or the target object throws an exception