• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Pass parameter to aop:before method in Spring

 
Ranch Hand
Posts: 281
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 :
 
Blueberry pie is best when it is firm and you can hold in your hand. Smell it. And smell this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic