Results 1 to 2 of 2

Thread: args(myObj) forces me to name variable as myObj

Hybrid View

  1. #1

    Default args(myObj) forces me to name variable as myObj

    If the exact name of the argument (which is myObj) from aroundUpdate is passed in as args(myObj) in my pointcut, then aroundUpdate successfully gets the corresponding object inside the body of aroundUpdate method.
    However, this forces the classes that that get intercepted by aroundUppdate method to name variable as myObj in the update method.

    For example, MyDao.update method has to have method signature as MyDao.update (IDomain myObj). In other words. myObj has to be the name of the argument for it to work. I cannot arbitrarily name it as apple, oragange, instead of myObj.

    The configuration shows below works, as long as the update method of classes have myObj as the name of the argument

    Code:
    <aop:aspect ref="dataEntryPoint">
    		<aop:pointcut
    			id="dataOperations" 
    			expression="execution(* org.*.data.*Dao.update*(..)) and args(myObj)" 
    		/>
    		<aop:around 
    			method="aroundUpdate" 
    			pointcut-ref="dataOperations"
    		/>
    	</aop:aspect>
    
    
    public Integer aroundUpdate(ProceedingJoinPoint pjp, IDomain myObj) throws Throwable{
    
    	// code
    }
    
    
    MyDao{
         public Integer update(IDomain myObj){
          // code
         }
    }

    Is there any way that I can use the fully qualified name of the IDomainObject (instead of myObj) in the above point cut expression?

    If I could use IDomainObject in args, as opposed to myObj in the pointcut and could get a handle of the object inside the body of atroundUpdate, that would have solved my purpose.

    When I try putting IDomainObject in pointcut as args(org.IDomainObject) and keep update method in MyDao as update(IDomain myObj), I get excception as:

    Code:
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name '_protectPointcutPostProcessor': BeanPostProcessor before instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.aop.aspectj.AspectJPointcutAdvisor#1': Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.aop.aspectj.AspectJPointcutAdvisor]: Constructor threw exception; nested exception is java.lang.IllegalArgumentException: error at ::0 formal unbound in pointcut 
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:405)
    	at java.security.AccessController.doPrivileged(AccessController.java:219)

    According to Spring documentation, I can do so.

    There is a similar proof in:
    HTML Code:
    http://denis-zhdanov.blogspot.com/2009/07/spring-aop-filtering-invocations-by.html
    Ideal situation would be to create pointcut as args(org.IDomain) because evey update method of *Dao does take an instance of IDomain as an argument. But I get exception when I try doing so, as shown above.

    My goal is NOT to be forced to put the name of the argument as myObj for every update method of Dao that needs to invoke this point cut.

    Could anyone please suggest what I am missing?

    Could anybody suggest any variation in pointcut that will get me around?

    Is there any other alternative?

  2. #2

    Default

    I stand corrected.

    I can have argument in MyDao update method as update(IDomain xyz) using the configuration that I posted.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •