java - Specifying the order of proxy creation in Spring -


i have spring application have following skeleton class

class servicecaller {     public result callservice()     {         //call remote service     } } 

since calling remote service expensive operation, added caching in application. used ehcache spring annotations @cacheable , applied callservice() method. working fine , result objects getting correctly cached.

later wanted add logger across servicecallers such logger record every actual call remote service. did not want manually add logger.info() every such callservice method decided use spring aop implement this.

i defined pointcut after-returning methods wanted log. working; noticed logger point cut invoked when had cache hit , actual callservice method not called. this, observed, happening because order of proxy servicecaller bean follows: aoppointcutproxy(ehcachecachingproxy(servicecallerbean)). want logger pointcut invoked when actual callservice method called , not when returning cached value ehcache proxy. means want proxy creation hierarchy in form of ehcachecachingproxy(aoppointcutproxy(servicecallerbean)). note bean definitions, pointcut definitions, cache configs may in different randomly named xml files.

so how enforce spring create proxies in order want?

that ordered interface used for. need implement on beans.

you can create proxy gets of proxies injected should surround call. composite proxy surrounds actual bean. upon invocation calls injected proxies in specified order.


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -