Announcement Announcement Module
Collapse
No announcement yet.
IllegalArgumentException: name binding only allowed in target, this, and args pcds Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • IllegalArgumentException: name binding only allowed in target, this, and args pcds

    Hi,
    I am trying to decouple an application service (MessageService) from a the business service layer but can't figure out what is wrong with my configuration:

    Case: When a business service that needs to send messages executes its sendMessages method
    Code:
    public void sendMessages(SomeObject obj) {}
    execute MessageService.send()
    Code:
    public class MessageService implements IMessageService, AfterAdvice{
     public void send(List<RecipientDO> recipients, MessageDO message) {..}
    }
    Code:
     <aop:config>
           <aop:aspect ref="messageService">
                <aop:after-returning pointcut="execution(* com.foo.services.SomeBusinessService.sendMessages(recipients,message))"
                                     method="send" arg-names="recipients,message"/>
           </aop:aspect>
        </aop:config>
    the message service
    Code:
     <bean id="messageService" class="com.foo.messaging.services.MessageService"
              p:messageFrom="${messaging.messageFrom}" p:messageTo="${messaging.messageTo}"
              p:messageCc="${messaging.messageCc}" p:messageBcc="${messaging.messageBcc}"
              p:faxConfirmationTo="${messaging.faxConfirmationTo}" p:faxTo="${messaging.faxTo}">
            <property name="recipientListDAO" ref="recipientListDAO"/>
            <property name="businessEmailSender" ref="busMessageSenderBean"/>
            <property name="faxSender" ref="faxSenderBean"/>
            <property name="messageDAO">
                <bean id="messageDAO" parent="sqlMapService" class="com.foo.messaging.dao.MessageDAO"/>
            </property>
            <property name="logDAO">
                <bean id="logDAO" parent="sqlMapService" class="com.foo.messaging.dao.LogDAO"/>
            </property>
        </bean>
    Code:
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'loggerListener' defined in class path resource [applicationContext-acegi-security.xml]: BeanPostProcessor before instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.aop.aspectj.AspectJPointcutAdvisor#2': 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 name binding only allowed in target, this, and args pcds
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:481)
    	at java.security.AccessController.doPrivileged(Native Method)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:455)
    	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:251)
    	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:169)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:248)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:170)
    	at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeansOfType(DefaultListableBeanFactory.java:296)
    	at org.springframework.context.support.AbstractApplicationContext.getBeansOfType(AbstractApplicationContext.java:950)
    	at org.springframework.context.support.AbstractApplicationContext.registerListeners(AbstractApplicationContext.java:711)
    	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:366)
    	at org.springframework.test.AbstractSingleSpringContextTests.createApplicationContext(AbstractSingleSpringContextTests.java:243)
    	at org.springframework.test.AbstractSingleSpringContextTests.loadContextLocations(AbstractSingleSpringContextTests.java:212)
    	at org.springframework.test.AbstractSingleSpringContextTests.loadContext(AbstractSingleSpringContextTests.java:187)
    	at org.springframework.test.AbstractSpringContextTests.getContext(AbstractSpringContextTests.java:140)
    	at org.springframework.test.AbstractSingleSpringContextTests.setUp(AbstractSingleSpringContextTests.java:100)
    	at org.springframework.test.ConditionalTestCase.runBare(ConditionalTestCase.java:76)
    	at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:40)
    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    	at com.intellij.rt.execution.application.AppMain.main(AppMain.java:90)
    Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.aop.aspectj.AspectJPointcutAdvisor#2': 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 name binding only allowed in target, this, and args pcds
    	at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:231)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:957)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:869)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:514)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:485)
    	at java.security.AccessController.doPrivileged(Native Method)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:455)
    	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:251)
    	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:169)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:248)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:170)
    	at org.springframework.aop.framework.autoproxy.BeanFactoryAdvisorRetrievalHelper.findAdvisorBeans(BeanFactoryAdvisorRetrievalHelper.java:87)
    	at org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator.findCandidateAdvisors(AbstractAdvisorAutoProxyCreator.java:98)
    	at org.springframework.aop.aspectj.autoproxy.AspectJAwareAdvisorAutoProxyCreator.shouldSkip(AspectJAwareAdvisorAutoProxyCreator.java:105)
    	at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.postProcessBeforeInstantiation(AbstractAutoProxyCreator.java:244)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInstantiation(AbstractAutowireCapableBeanFactory.java:828)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.resolveBeforeInstantiation(AbstractAutowireCapableBeanFactory.java:799)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:475)
    	... 32 more
    Caused by: 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 name binding only allowed in target, this, and args pcds
    	at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:98)
    	at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:87)
    	at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:225)
    	... 49 more
    Caused by: java.lang.IllegalArgumentException: error at ::0 name binding only allowed in target, this, and args pcds
    	at org.aspectj.weaver.tools.PointcutParser.parsePointcutExpression(PointcutParser.java:315)
    	at org.springframework.aop.aspectj.AspectJExpressionPointcut.buildPointcutExpression(AspectJExpressionPointcut.java:197)
    	at org.springframework.aop.aspectj.AspectJExpressionPointcut.checkReadyToMatch(AspectJExpressionPointcut.java:184)
    	at org.springframework.aop.aspectj.AspectJExpressionPointcut.getMethodMatcher(AspectJExpressionPointcut.java:170)
    	at org.springframework.aop.aspectj.AbstractAspectJAdvice.buildSafePointcut(AbstractAspectJAdvice.java:189)
    	at org.springframework.aop.aspectj.AspectJPointcutAdvisor.<init>(AspectJPointcutAdvisor.java:51)
    	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
    	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
    	at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
    	at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:83)
    	... 51 more

  • #2
    Your pointcut needs to be changed.

    Replace:
    Code:
    execution(* com.foo.services.SomeBusinessService.sendMessages(recipients,message))
    with:
    Code:
    execution(* com.foo.services.SomeBusinessService.sendMessages(*,*)) 
    and args(recipients,message)

    Comment


    • #3
      Pointcut fixed

      Hi Ramnivas, thank you so much, this does fix my pointcut config and solve the error, however the MessageService.send method that the aop config should trigger after successfully returning the businessService's sendMessages method is not triggered. All of my other aop configurations are working so there is something i am missing/misconfiguring in this instance. Any suggestions?

      thankyou,
      Holly

      Comment


      • #4
        Holly,

        The problem is that the pointcut isn't matching any method. In earlier message, I focused on pointcut error. However, taking a closer look, your pointcut (and my modifications to it) expects two arguments: recipient and message. The message is available as the argument; however, you need to find another way to grab recipients. It seems that you are trying to send a message to a potentially configurable set of recipients. In that case, you may do something along the following lines:

        Pointcut:
        Code:
        execution(* com.foo.services.SomeBusinessService.sendMessages(*)) 
        and args(message)
        Aspect:
        Code:
        public class MessageBroadcaster {
            // MessageService unchnaged from your definition, but implementing AfterAdvice is unnecessary
            MessageService messageService;
        
            List<RecipientDO> recipients; // add setter
        
            public void send(Object message) {
                messageService.send(recipients, message);
            }
        }
        Configuration:
        Code:
         <aop:config>
               <aop:aspect ref="messageBroadcaster">
                    <aop:after-returning pointcut="execution(* com.foo.services.SomeBusinessService.sendMessages(message))"
                                         method="send" arg-names="message"/>
               </aop:aspect>
            </aop:config>
        Of course, you will have a bean for messageBroadcaster injected with a MessageService bean and a recipient list.

        -Ramnivas

        Comment

        Working...
        X