• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

Pass parameter to aop:before method in Spring  RSS feed

 
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).
 
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 :
 
The harder you work, the luckier you get. This tiny ad brings luck - just not good luck or bad luck.
how do I do my own kindle-like thing - without amazon
https://coderanch.com/t/711421/engineering/kindle-amazon
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!