• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Pass parameter to aop:before method in Spring

 
Sam Gehouse
Ranch Hand
Posts: 281
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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é
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 :
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic