Announcement Announcement Module
Collapse
No announcement yet.
Pass parameter to method that gets executed as AOP:Before Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Pass parameter to method that gets executed as AOP:Before

    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:

    Code:
    MyDomain myDomain = new MyDomain();
    MyDao.update(myDomain);
    MyDomain is not registered as a Spring bean. MyDao is registered as a bean in Spring and it implements IDao.


    My XML is:
    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>
    IDao also has update(IDomain obj) method that is implemented by myDao.

    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.

  • #2
    Following configuration did work for me:

    Code:
    <aop:config>
    	<aop:aspect ref="myDao">
    		<aop:pointcut
    			id="updateOperations" 
    			expression="execution(* poc.IDao.update*(..)) and args(obj)" />
    		<aop:before
    			method="update" 
    			pointcut-ref="updateOperations"/>
    	</aop:aspect>
    </aop:config>

    Comment

    Working...
    X