Announcement Announcement Module
No announcement yet.
AOP to generate ApplicationEvents Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • AOP to generate ApplicationEvents

    We have employees, for example. EmployeeDAO and the standard hibernatetemplate stuff with OpenSessionInViewInterceptor. It's all working fine. The "owned" objects (declared in the mapping) are cascade deleted successfully.
    As we add new subsystems to the application, we find other domain objects which refer to an association with an employee. We would like to be able to add such subsystems without having to alter the existing mapping of the Employee - we're using XDoclet to generate those by the way. The Employee doesn't own these other objects (object graphs), doesn't own the associations, to be exact doesn't even know they exist.

    Some of these other systems are interested in Employee delete events. I may not have access to the EmployeeDAO code, so I can't just add new methods to it to generate or publish events. Is AOP an answer here? Can I intercept delete methods in various DAOs and have them publish EmployeeDeleteApplicationEvents, so to speak? Is this a path worth pursuing, does anybody here have experience with similar situations?

    I don't see a lot in the docs about ApplicationEvents, I would also appreciate any advice as to their successful implemention in Spring.


  • #2
    Yes you could intercept delete methods on your DAOs and publish an ApplicationEvent. We use ApplicationEvent extensively within Acegi Security. It's pretty straight-forward, it just works.

    In relation to your interceptor, the easiest way is to write an implementation of MethodInterceptor, extend Spring's StaticMethodMatcherPointcutAdvisor, and use a DefaultAdvisorAutoProxyCreator in your application context. I posted some source code for a similar DAO advisor and interceptor at You'd just need your MethodInterceptor to implement ApplicationContextAware to get hold of the ApplicationContext so it can applicationContext.publishEvent(yourEvent).
    Last edited by robyn; May 14th, 2006, 11:58 AM.