Announcement Announcement Module
Collapse
No announcement yet.
around advice failing with annotation parameter Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • around advice failing with annotation parameter

    Okay, have a look at this...

    Code:
        @Before("within(net.company.hierarchy..*) && @annotation(security)")
        public void before(JoinPoint jp, Security security) {
            logger.info("before advice:" + security.groups().length);
        }
    Works absolutely fine.

    However, this...
    Code:
        @Around(value="execution(* net.company.hierarchy.service..*.*(..)) && @annotation(security)")
        public Object around(ProceedingJoinPoint pjp, Security security) throws Throwable {
            logger.info("around advice:" + security.groups().length);
            return pjp.proceed();
    
        }
    ...fail with this stack stace...

    Code:
    java.lang.IllegalStateException: Required to bind 2 arguments, but only bound 1 (JoinPointMatch was NOT bound in invocation)
    	at org.springframework.aop.aspectj.AbstractAspectJAdvice.argBinding(AbstractAspectJAdvice.java:510)
    	at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethod(AbstractAspectJAdvice.java:556)
    	at org.springframework.aop.aspectj.AspectJAroundAdvice.invoke(AspectJAroundAdvice.java:57)
    I am using Spring 2.0 and AspectJ 1.5.2a and I am intercepting xfire 1.2.2 webservice exposed methods.

    I've tried changing 'execution' to 'within'. Same error.

    The old spring 1.2 AOP method works fine with the xfire system, I am just attempting an upgrade of my aspects to AspectJ/Spring 2.0.

    Have I found a bug or am I doing something wrong??

    Thanks,
    James

  • #2
    I've just tested my code with 2.0-rc4 as suggested here...
    http://forum.springframework.org/showthread.php?t=29858

    ...and it works!

    Does this confirm it as a 2.0 final bug...?

    Comment


    • #3
      Originally posted by jimsey View Post
      I've just tested my code with 2.0-rc4 as suggested here...
      http://forum.springframework.org/showthread.php?t=29858

      ...and it works!

      Does this confirm it as a 2.0 final bug...?
      Yes, unfortunately so. A change went into 2.0 final to fix an issue with proceeding multiple times in an advice body when there are multiple interceptors in a chain. This fix inadvertantly broke argument binding on the call to proceed in such circumstances. The bug doesn't show up unless you have multiple interceptors, so the AOP suite didn't catch it.

      I've raised SPR-2687 to cover this, and fixed the issue in the tree - it will be resolved in 2.0.1.

      Comment


      • #4
        Okay, thanks for that.

        I'll continue with rc4 for now, no problem.

        Comment


        • #5
          Binding annotation does not work

          Hello
          I tried this recently with Spring 2.0.1:

          Code:
          @Around(value="within(com.toyota.foo.Foo) and @annotation(Cacheable)")
          public Object doRetry(ProceedingJoinPoint pjp, Cacheable cacheable) throws Throwable {
              return pjp.proceed();
          		
          }
          I am getting:
          Code:
          org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'foo' defined in class path resource [cachingAspectApplicationContext.xml]: Cannot resolve reference to bean 'par' while setting bean property 'par'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'par' defined in class path resource [cachingAspectApplicationContext.xml]: Initialization of bean failed; nested exception is java.lang.IllegalArgumentException: error at ::0 formal unbound in pointcut 
          Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'par' defined in class path resource [cachingAspectApplicationContext.xml]: Initialization of bean failed; nested exception is java.lang.IllegalArgumentException: error at ::0 formal unbound in pointcut 
          Caused by: java.lang.IllegalArgumentException: error at ::0 formal unbound in pointcut 
          	at org.aspectj.weaver.tools.PointcutParser.parsePointcutExpression(PointcutParser.java:315)
          	at org.springframework.aop.aspectj.AspectJExpressionPointcut.buildPointcutExpression(AspectJExpressionPointcut.java:159)
          	at org.springframework.aop.aspectj.AspectJExpressionPointcut.checkReadyToMatch(AspectJExpressionPointcut.java:149)
          	at org.springframework.aop.aspectj.AspectJExpressionPointcut.getClassFilter(AspectJExpressionPointcut.java:134)
          	at org.springframework.aop.support.AopUtils.canApply(AopUtils.java:165)
          	at org.springframework.aop.support.AopUtils.canApply(AopUtils.java:225)
          	at org.springframework.aop.support.AopUtils.findAdvisorsThatCanApply(AopUtils.java:255)
          	at org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator.findEligibleAdvisors(AbstractAdvisorAutoProxyCreator.java:73)
          	at org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator.getAdvicesAndAdvisorsForBean(AbstractAdvisorAutoProxyCreator.java:57)
          	at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.postProcessAfterInitialization(AbstractAutoProxyCreator.java:255)
          	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsAfterInitialization(AbstractAutowireCapableBeanFactory.java:312)
          	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1033)
          	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:421)
          	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:245)
          	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:140)
          	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:242)
          	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:156)
          	at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:248)
          	at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:128)
          	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:950)
          	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:740)
          	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:417)
          	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:245)
          	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:140)
          	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:242)
          	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:156)
          	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:273)
          	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:346)
          	at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:92)
          	at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:77)
          	at com.toyota.tms.aspect.CachingAspectTest.testFoo(CachingAspectTest.java:20)
          	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
          	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
          	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
          	at java.lang.reflect.Method.invoke(Method.java:585)
          	at junit.framework.TestCase.runTest(TestCase.java:164)
          	at junit.framework.TestCase.runBare(TestCase.java:130)
          	at junit.framework.TestResult$1.protect(TestResult.java:110)
          	at junit.framework.TestResult.runProtected(TestResult.java:128)
          	at junit.framework.TestResult.run(TestResult.java:113)
          	at junit.framework.TestCase.run(TestCase.java:120)
          	at junit.framework.TestSuite.runTest(TestSuite.java:228)
          	at junit.framework.TestSuite.run(TestSuite.java:223)
          	at org.junit.internal.runners.OldTestClassRunner.run(OldTestClassRunner.java:35)
          	at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:38)
          	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
          	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
          	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
          	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
          	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
          Any ideas?

          Comment


          • #6
            I don't think you can use the word 'and' in your expression.

            Try && instead.

            Comment


            • #7
              &amp;&amp; versus 'and'

              I never noticed any difference between the two. It seems you can use '&&' or 'and' with the same effect.

              Comment


              • #8
                You can use 'and' for '&&', 'or' for '||' and 'not' for '!' only in schema-style AOP pointcuts (in XML). This is allowed only to simplify expressing '&&'. Otherwise, you will have to write '&amp;&amp;' (which works, as well, BTW). For symmetry and readability, 'or' and 'not' are supported as well.

                When you use the @AspectJ syntax, you must use AspectJ's pointcut syntax which does not support 'and', 'or' or 'not'.

                -Ramnivas

                Comment


                • #9
                  Similar Error

                  I am experiencing a similar issue. I am using Spring 2.0.3.

                  SystemArchitecture class:
                  Code:
                  @Pointcut("execution(* com.xyz.abc.rsw.dao.*.*(..))")
                      public void daoOperation() {}
                  Aspect Class:
                  Code:
                  @Around(value = "com.xyz.abc.rsw.aop.SystemArchitecture.daoOperation() &&" +
                  			" @annotation(com.xyz.abc.rsw.DataAccess.DataAccessMethod)", 
                  			argNames="method")
                  	public Object doAPMProfiling(ProceedingJoinPoint pjp, DataAccessMethod method)
                  			throws Throwable {
                  		
                  		// start timer
                  		TransientInstrument apmTimer = null;		
                  		try {
                  			TimerInstrument t = monitoringFactory.getTimer(method.timerName());
                  			apmTimer = t.getTransientInstrument();
                  			apmTimer.begin();
                  		} catch (Exception e) {
                  			// Failed to get a timer. No matter what the reason, continue on
                  			// as the timer is only for monitoring.
                  		}
                  
                  		Exception serviceException = null;
                  		try {
                  			//call method on target object
                  			return pjp.proceed();
                  		} catch (Exception e) { //catch everything
                  			serviceException = e;
                  			throw e; //throw it so that calling code can handle it
                  		} finally {
                  			//stop timer
                  			if (apmTimer != null) {
                  				if (serviceException != null) {
                  					apmTimer.update(serviceException);
                  				} else {
                  					apmTimer.update();
                  				}
                  			}
                  		}
                  	}

                  Annotated method:
                  Code:
                  	@DataAccessMethod(timerName="/apm/timer/service=XTRAC,view=RetrieveWorkItem")
                  	public RetrieveWorkItemResponse retrieveWorkItem(RetrieveWorkItem retrieveWorkItemRequest, String cookie) throws BaseException{
                  I'm getting:

                  Code:
                  org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'rswInstrumentManager' defined in class path resource [spring/monitoringSupport.xml]: Initialization of bean failed; nested exception is java.lang.IllegalArgumentException: error at ::0 formal unbound in pointcut 
                  Caused by: java.lang.IllegalArgumentException: error at ::0 formal unbound in pointcut 
                  	at org.aspectj.weaver.tools.PointcutParser.parsePointcutExpression(PointcutParser.java:315)
                  	at org.springframework.aop.aspectj.AspectJExpressionPointcut.buildPointcutExpression(AspectJExpressionPointcut.java:188)
                  	at org.springframework.aop.aspectj.AspectJExpressionPointcut.checkReadyToMatch(AspectJExpressionPointcut.java:175)
                  	at org.springframework.aop.aspectj.AspectJExpressionPointcut.getClassFilter(AspectJExpressionPointcut.java:156)
                  	at org.springframework.aop.support.AopUtils.canApply(AopUtils.java:187)
                  	at org.springframework.aop.support.AopUtils.canApply(AopUtils.java:244)
                  	at org.springframework.aop.support.AopUtils.findAdvisorsThatCanApply(AopUtils.java:274)
                  	at org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator.findEligibleAdvisors(AbstractAdvisorAutoProxyCreator.java:85)
                  	at org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator.getAdvicesAndAdvisorsForBean(AbstractAdvisorAutoProxyCreator.java:69)
                  	at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.postProcessAfterInitialization(AbstractAutoProxyCreator.java:277)
                  	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsAfterInitialization(AbstractAutowireCapableBeanFactory.java:318)
                  	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1119)
                  	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:431)
                  	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:254)
                  	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:144)
                  	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:251)
                  	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:163)
                  	at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeansOfType(DefaultListableBeanFactory.java:244)
                  	at org.springframework.context.support.AbstractApplicationContext.getBeansOfType(AbstractApplicationContext.java:746)
                  	at org.springframework.context.support.AbstractApplicationContext.registerListeners(AbstractApplicationContext.java:542)
                  	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:349)
                  	at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:241)
                  	at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:184)
                  	at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:49)
                  	at com.fmr.commons.webservices.config.StartupListener.contextInitialized(StartupListener.java:37)
                  	at com.ibm.ws.wswebcontainer.webapp.WebApp.notifyServletContextCreated(WebApp.java:608)
                  	at com.ibm.ws.webcontainer.webapp.WebApp.commonInitializationFinish(WebApp.java:266)
                  	at com.ibm.ws.wswebcontainer.webapp.WebApp.initialize(WebApp.java:272)
                  	at com.ibm.ws.wswebcontainer.webapp.WebGroup.addWebApplication(WebGroup.java:88)
                  	at com.ibm.ws.wswebcontainer.VirtualHost.addWebApplication(VirtualHost.java:157)
                  	at com.ibm.ws.wswebcontainer.WebContainer.addWebApp(WebContainer.java:655)
                  	at com.ibm.ws.wswebcontainer.WebContainer.addWebApplication(WebContainer.java:608)
                  	at com.ibm.ws.webcontainer.component.WebContainerImpl.install(WebContainerImpl.java:333)
                  	at com.ibm.ws.webcontainer.component.WebContainerImpl.start(WebContainerImpl.java:549)
                  	at com.ibm.ws.runtime.component.ApplicationMgrImpl.start(ApplicationMgrImpl.java:1295)
                  	at com.ibm.ws.runtime.component.DeployedApplicationImpl.fireDeployedObjectStart(DeployedApplicationImpl.java:1129)
                  	at com.ibm.ws.runtime.component.DeployedModuleImpl.start(DeployedModuleImpl.java:567)
                  	at com.ibm.ws.runtime.component.DeployedApplicationImpl.start(DeployedApplicationImpl.java:814)
                  	at com.ibm.ws.runtime.component.ApplicationMgrImpl.startApplication(ApplicationMgrImpl.java:948)
                  	at com.ibm.ws.runtime.component.ApplicationMgrImpl$1.run(ApplicationMgrImpl.java:1478)
                  	at com.ibm.ws.security.auth.ContextManagerImpl.runAs(ContextManagerImpl.java:3811)
                  	at com.ibm.ws.security.auth.ContextManagerImpl.runAsSystem(ContextManagerImpl.java:3893)
                  	at com.ibm.ws.security.core.SecurityContext.runAsSystem(SecurityContext.java:245)
                  	at com.ibm.ws.runtime.component.ApplicationMgrImpl.startApplication(ApplicationMgrImpl.java:1483)
                  	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                  	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:64)
                  	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
                  	at java.lang.reflect.Method.invoke(Method.java:615)
                  	at sun.reflect.misc.Trampoline.invoke(MethodUtil.java:62)
                  	at sun.reflect.GeneratedMethodAccessor57.invoke(Unknown Source)
                  	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
                  	at java.lang.reflect.Method.invoke(Method.java:615)
                  	at sun.reflect.misc.MethodUtil.invoke(MethodUtil.java:265)
                  	at javax.management.modelmbean.RequiredModelMBean.invokeMethod(RequiredModelMBean.java:1089)
                  	at javax.management.modelmbean.RequiredModelMBean.invoke(RequiredModelMBean.java:971)
                  	at com.sun.jmx.mbeanserver.DynamicMetaDataImpl.invoke(DynamicMetaDataImpl.java:231)
                  	at com.sun.jmx.mbeanserver.MetaDataImpl.invoke(MetaDataImpl.java:238)
                  	at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:833)
                  	at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:802)
                  	at com.ibm.ws.management.AdminServiceImpl$1.run(AdminServiceImpl.java:1057)
                  	at com.ibm.ws.security.util.AccessController.doPrivileged(AccessController.java:118)
                  	at com.ibm.ws.management.AdminServiceImpl.invoke(AdminServiceImpl.java:950)
                  	at com.ibm.ws.management.commands.AdminServiceCommands$InvokeCmd.execute(AdminServiceCommands.java:251)
                  	at com.ibm.ws.console.core.mbean.MBeanHelper.invoke(MBeanHelper.java:239)
                  	at com.ibm.ws.console.appdeployment.ApplicationDeploymentCollectionAction.execute(ApplicationDeploymentCollectionAction.java:536)
                  	at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:484)
                  	at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:274)
                  	at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1486)
                  	at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:528)
                  	at javax.servlet.http.HttpServlet.service(HttpServlet.java:763)
                  	at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
                  	at  ............
                  Any thoughts?

                  Comment


                  • #10
                    I am having this same issue in 2.0.5 (Before and After advice working, but not Around). Has this been resolved yet?

                    Comment


                    • #11
                      BTW, I just bit the bullet and upgraded to Spring 2.5.4. Problem solved.

                      Comment

                      Working...
                      X