Announcement Announcement Module
No announcement yet.
Intercepting Specific Methods Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Intercepting Specific Methods


    In our application we need to intercept some methods to include information in a Thread Local variable.
    Our sequence diagram:

    Controller -> DAO -> Queries -> Data Source

    I need to intercept some methods of the Controller layer because, depending on the method, the application should use one data source or another (actually there is more than 10), and this behaviour is dynamic, ie, it depends on parameters provided when calling the methods, so I can not use the Spring XML for this purpose.

    I would like something like this (the interceptor tag is just my imagination):

    <bean id="myController" singleton="false"
    <interceptor method="doSomething" class="MyInterceptorClass"/>

    Is there something in Spring I can use for this?


  • #2
    Yes, take a look at ProxyFactoryBean. You can add an advice to your bean, which will intercept the methods and based on logic you desire, change the ThreadLocal variable.
    Take a look at the reference documentation and the javadocs for more information.,