Matej Tymes's Weblog: Spring proxy - calling methods within the same service
One of the bigest issues of spring aop is, that when you use its proxies for adding some aop functionality (like for example transactions or security), your calls to a method withing the same bean won't trigger the advised aop functionality.
So if you have a Service, that has two methods, where method A() HAS NO @Transactional annotation and method B() HAS a @Transactional annotation and non transactional method A() calls during its execution transactional method B() then spring won't start any transaction. This is because the spring proxy will redirect its call for A() to the service object but the call to B() won't be executed on the proxy (that knows how and when to start the transaction) but instead on the actual service object that has not functional code to start the transaction (only a @Transactional annotation on the method B()).
To overcome this problem I have implemented a simple solution that injects the proxy of current bean instance and then you execute advised methods calling this instance proxy variable. All you have use is a @ThisInstance annotation and register a custom BeanPostProcessor:
Read full article from Matej Tymes's Weblog: Spring proxy - calling methods within the same service
No comments:
Post a Comment