Announcement Announcement Module
No announcement yet.
PerformanceMonitorInterceptor and abstract base classes Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • PerformanceMonitorInterceptor and abstract base classes


    I have an abstract base class which declares an abstract init and destroy method. All my beans inherit an abstract bean definition which hooks up the init and destroy methods so that the container invokes them on startup, etc.

    Is it possible to declare a pointcut to monitor the performance throughout the service layer on all the implemented init() and destroy() methods?

    I have successfully implemented the PerformanceMonitorInterceptor, but I can't get the pointcut right so it will be triggered when the container invokes the init method. Should this mechanism rather be used on interfaces than abstract base classes?

    Thanks in advance.

  • #2
    Found the answer...

    I found the following paragraph in the Spring documentation: "A target bean is fully created first, then an AOP proxy (for example) with its interceptor chain is applied". That answers my question.

    Finally, please be aware that the Spring container guarantees that a configured initialization callback is called immediately after a bean has been supplied with all of its dependencies. This means that the initialization callback will be called on the raw bean reference, which means that any AOP interceptors or suchlike that will ultimately be applied to the bean will not yet be in place. A target bean is fully created first, then an AOP proxy (for example) with its interceptor chain is applied. Note that, if the target bean and the proxy are defined separately, your code can even interact with the raw target bean, bypassing the proxy. Hence, it would be very inconsistent to apply the interceptors to the init method, since that would couple the lifecycle of the target bean with its proxy/interceptors and leave strange semantics when talking to the raw target bean directly.
    This appears under the heading Default initialization & destroy methods on page