File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Other Application Frameworks and the fly likes Pass parameter to aop:before method in Spring Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Other Application Frameworks
Bookmark "Pass parameter to aop:before method in Spring" Watch "Pass parameter to aop:before method in Spring" New topic

Pass parameter to aop:before method in Spring

Sam Gehouse
Ranch Hand

Joined: Jul 21, 2003
Posts: 281
I will appreciate an example on how to pass parameter to the method that gets executed as AOP:Before using XML configuration in Spring.

DaoUtil.beforeUpdate(Idomain obj) method has to get executed as aop:before, when an implementation of IDao.update(IDomain obj) is executed.

My test class is like:

MyDomain is not registered as a Spring bean. MyDao is registered as a bean in Spring and it implements IDao. As such, myDao implements update(IDomain) method from IDao.

My XML is:

IDao also has update(IDomain obj) method that is implemented by myDao. Note that IDao.update(IDomain) returns an integer.

I would like DaoUtil.beforeUpdate(Idomain obj) method to get executed before myDao.update(IDomain) get executed using aop:before. I would also like DaoUtil.beforeUpdate(Idomain obj) method to get the instance of IDomain that was set by my test case.

I get exception with the above configuration.

However, using the above configuration, if I took out IDomain parameter from DaoUtil.update method and wrote another overloaded method as DaoUtil.beforeUpdate(), then it works without throwing any exception. And, the new overloaded method DaoUtil.beforeUpdate() is the one that gets executed as aop:before.

However DaoUtil.beforeUpdate() method will not suffice my purpose. My goal is to get the instance of IDomain as a parameter in DaoUtil.beforeUpdate(IDomain) method. I want DaoUtil.beforeUpdate(IDomain) method to get executed as AOP:Before before, when any method implementing IDao.update(IDomain) gets executed.

Please advice the proper configuration using XML so that I can pass parameter to the aop:before method. In other words, I would like to pass parameter IDomain (that was set by my test class) to DaoUtil.beforeUpdate(IDomain) which in turn gets executed as aop:before before calling myDao.update(IDomain).
Christophe Verré

Joined: Nov 24, 2005
Posts: 14687

I don't see any reference to DaoUtil.beforeUpdate in your advice. Is this your complete configuration ?

Here is one way to make it work :

[My Blog]
All roads lead to JavaRanch
I agree. Here's the link:
subject: Pass parameter to aop:before method in Spring
Similar Threads
Simple AOP not working
Spring AOP program not running as expected
Spring AOP issue
Can AOP work with BeanFactory Resource Implementation ?
Spring 2.5 and AOP - BeanPostProcessor before instantiation of bean failed