I will appreciate an example on how to pass parameter to the method that gets executed as AOP:Before using XML configuration.
DaoUtil.beforeUpdate(Idomain obj) method gets 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.Code:MyDomain myDomain = new MyDomain(); MyDao.update(myDomain);
My XML is:
IDao also has update(IDomain obj) method that is implemented by myDao.Code:<aop:config> <aop:aspect ref="myDao"> <aop:pointcut id="updateOperations" expression="execution(* poc.IDao.update*(..))" /> <aop:before method="update" arg-names="obj" pointcut-ref="updateOperations"/> </aop:aspect> </aop:config>
I would like DaoUtil.beforeUpdate(Idomain obj) method to get executed before myDao.update(IDomain) get executed. 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, DaoUtil.beforeUpdate() is the method that gets executed as aop:before.
However, that 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 my IDao.update(IDomain) get executed.
Note that IDao.update(IDomain) returns an integer.
Please advice the proper configuration using XML so that I can pass parameter to the aop:before method.


Reply With Quote