Announcement Announcement Module
Collapse
No announcement yet.
Can't find referenced pointcut in Java 6 Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Can't find referenced pointcut in Java 6

    I have configured a logging aspect with Spring 2.0.7 using auto-wiring and aspectj. Following the documentation, I've created a SystemArchitecture class:
    Code:
    @Aspect public class SystemArchitecture {
      @Pointcut("within(com.mycompany..*)")
      public void inAllApplication() {}
    }
    And here is my logging aspect:
    Code:
    package com.mycompany.myapp.logging.server.utilities;
    
    import org.apache.commons.logging.Log;
    import org.apache.commons.logging.LogFactory;
    
    import org.aspectj.lang.JoinPoint;
    import org.aspectj.lang.annotation.After;
    import org.aspectj.lang.annotation.AfterReturning;
    import org.aspectj.lang.annotation.AfterThrowing;
    import org.aspectj.lang.annotation.Aspect;
    import org.aspectj.lang.annotation.Before;
    
    import org.springframework.core.Ordered;
    
    @Aspect public class ServerSideLogger
      implements Ordered {
    
      public ServerSideLogger() {
        LogFactory.getLog(ServerSideLogger.class)
                  .info("Initializing server-side logger");
      }
    
      @AfterReturning(
                      pointcut = "com.mycompany.myapp.logging.server.utilities.SystemArchitecture.inAllApplication()",
                      returning = "returnValue"
                     )
      public void logOperationSuccess(JoinPoint logged,
                                      Object returnValue) {
        Log log = getLog(logged);
        log.info("Successful operation " + getLoggedOperationDescription(logged));
        if (log.isTraceEnabled()) {
          log.trace("Operation returned: " + returnValue);
        }
      }
    
      public int getOrder() {
        return order;
      }
    
      public void setOrder(int order) {
        this.order = order;
      }
    
      private Log getLog(JoinPoint logged) {
        return LogFactory.getLog(logged.getTarget().getClass());
      }
    
      private String getLoggedOperationDescription(JoinPoint logged) {
        return "[" + logged.getTarget()
                           .getClass()
                           .getName() + "." + logged.getSignature()
                                                    .getName() + "]";
      }
      
      private int order;
    }
    Then all of this is configured with the following application context:
    Code:
    <beans xmlns="http://www.springframework.org/schema/beans" 
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xmlns:aop="http://www.springframework.org/schema/aop"
           xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
                               http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd">
    	<aop:aspectj-autoproxy/>
    	
    	<bean id="serverSideLogger" 
    		class="com.mycompany.myapp.logging.server.utilities.ServerSideLogger" />
    	
    	<bean id="loggingSystemArchitecture" 
    		class="com.mycompany.myapp.logging.server.utilities.SystemArchitecture" />
    </beans>
    My problem is that it works great when Tomcat is running on Java 5, but when I start up on Java 6, I get the following exception:
    Code:
    2007-11-20 15:32:26,656 *** ERROR *** context.ContextLoader *** Context initialization failed
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.aop.aspectj.AspectJPointcutAdvisor': Cannot resolve reference to bean 'txAdvice' while setting bean property 'advice'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'txAdvice': Cannot resolve reference to bean 'txManager' while setting bean property 'transactionManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'txManager' defined in class path resource [com/mycompany/security/kmc/server/noncritical/persistence/spring-kmc-javabean-persistence-hibernate.xml]: Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [com/mycompany/security/kmc/server/noncritical/persistence/spring-kmc-javabean-persistence-hibernate.xml]: Cannot resolve reference to bean 'dataSource' while setting bean property 'dataSource'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [com/mycompany/security/kmc/server/noncritical/persistence/spring-kmc-javabean-persistence-base.xml]: Initialization of bean failed; nested exception is java.lang.IllegalArgumentException: error at ::0 can't find referenced pointcut inAllApplication
    Caused by: 
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'txAdvice': Cannot resolve reference to bean 'txManager' while setting bean property 'transactionManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'txManager' defined in class path resource [com/mycompany/security/kmc/server/noncritical/persistence/spring-kmc-javabean-persistence-hibernate.xml]: Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [com/mycompany/security/kmc/server/noncritical/persistence/spring-kmc-javabean-persistence-hibernate.xml]: Cannot resolve reference to bean 'dataSource' while setting bean property 'dataSource'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [com/mycompany/security/kmc/server/noncritical/persistence/spring-kmc-javabean-persistence-base.xml]: Initialization of bean failed; nested exception is java.lang.IllegalArgumentException: error at ::0 can't find referenced pointcut inAllApplication
    Caused by: 
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'txManager' defined in class path resource [com/mycompany/security/kmc/server/noncritical/persistence/spring-kmc-javabean-persistence-hibernate.xml]: Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [com/mycompany/security/kmc/server/noncritical/persistence/spring-kmc-javabean-persistence-hibernate.xml]: Cannot resolve reference to bean 'dataSource' while setting bean property 'dataSource'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [com/mycompany/security/kmc/server/noncritical/persistence/spring-kmc-javabean-persistence-base.xml]: Initialization of bean failed; nested exception is java.lang.IllegalArgumentException: error at ::0 can't find referenced pointcut inAllApplication
    Caused by: 
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [com/mycompany/security/kmc/server/noncritical/persistence/spring-kmc-javabean-persistence-hibernate.xml]: Cannot resolve reference to bean 'dataSource' while setting bean property 'dataSource'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [com/mycompany/security/kmc/server/noncritical/persistence/spring-kmc-javabean-persistence-base.xml]: Initialization of bean failed; nested exception is java.lang.IllegalArgumentException: error at ::0 can't find referenced pointcut inAllApplication
    Caused by: 
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [com/mycompany/security/kmc/server/noncritical/persistence/spring-kmc-javabean-persistence-base.xml]: Initialization of bean failed; nested exception is java.lang.IllegalArgumentException: error at ::0 can't find referenced pointcut inAllApplication
    Caused by: 
    java.lang.IllegalArgumentException: error at ::0 can't find referenced pointcut inAllApplication
    	at org.aspectj.weaver.tools.PointcutParser.parsePointcutExpression(PointcutParser.java:315)
    	at org.springframework.aop.aspectj.AspectJExpressionPointcut.buildPointcutExpression(AspectJExpressionPointcut.java:172)
    	at org.springframework.aop.aspectj.AspectJExpressionPointcut.checkReadyToMatch(AspectJExpressionPointcut.java:162)
    	at org.springframework.aop.aspectj.AspectJExpressionPointcut.getClassFilter(AspectJExpressionPointcut.java:103)
    	at org.springframework.aop.support.AopUtils.canApply(AopUtils.java:171)
    	at org.springframework.aop.support.AopUtils.canApply(AopUtils.java:231)
    ....
    Any idea? Do I need to add something to my pointcut declarations in SystemArchitecture so that I can have a JoinPoint argument in the aspect method?

  • #2
    I'm really stuck on that.
    Has anybody ever seen that and could help me?

    Comment


    • #3
      I just post an example on this.
      You may take a look.
      The problem you have is that you need to define:
      @Pointcut("your-advice-method-go-here")
      public myAdvice(){...}

      @AfterReturning(pointcut="myAdvice", returning="returnVal")
      ...

      The developer guide is very confusing. I had the exactly same problem yesterday.

      Hope this help.

      --Gary

      Comment


      • #4
        I don't understand. I don't see the difference between what you're suggesting and my code. Could you be more precise or give me a link to the example you gave?

        Comment


        • #6
          No it doesn't work. The only difference between your code and my code is that my pointcuts are defined in another class.

          By the way, have you tested your example with a Java 6 runtime? Because that's why I think it has nothing to do with my pointcuts: it works great in Java 5, and this exception appears only when I start Tomcat on Java 6.

          Comment


          • #7
            Sebastian,
            It works for JDK6.3 too. if you want your way, here is the format:
            Code:
            //	@Pointcut("execution(* testReturnVal(..))")
            	@Pointcut("execution(int com.dcci.spring.aop.HelloService.testReturnVal())")
            	public void anotherMethod() {
            	}
            	
            	@AfterReturning(pointcut="anotherMethod()", returning="retVal")
            	public void doAccessCheck(Object retVal) {
            		System.out.println("retVal=" + retVal);
            		System.out.println("Another......");
            	}
            The important thing is that you need to provide full signature like:

            Code:
            @Pointcut("execution(int com.dcci.spring.aop.HelloService.testReturnVal())")
            	public void anotherMethod() {
            	}
            It seems you didn't give the return type, [void].

            Let me know this works or not.

            Thanks,

            --Gary

            Comment


            • #8
              Hi,

              I have the same problem. Do you have any solution?
              This Error came when I switched on Java 6. Using a new aspectJ-Version solved the problem when compiling but I have still the problem running the server on Java 6.
              Hope anyone can help...

              Comment


              • #9
                Code:
                @Pointcut("execution(public void refresh()) && within(de.xy.remote.service..*)")
                public void refreshables() {}
                
                @AfterThrowing(pointcut="refreshables()", throwing="t")
                public void handle(JoinPoint jp, final Throwable t) {
                Log log = LogFactory.getLog(jp.getTarget().getClass());
                log.error("Caught Exception with AOP on Thread: "
                + Thread.currentThread().getName()+" Exception: ", t);
                exceptionReporter.setThrownException(t);
                }
                I use 3 PointCuts in my application and since Java 6 I get exceptions. "Can't find referenced pointcut..."

                In Java 5 I never had a problem and I don't see any error in my code. Can you help me?

                Comment


                • #10
                  This is a known bug in AspectJ version 1.5.3 and prior. You need to use AspectJ 1.5.4 or AspectJ 1.6.x.

                  Also, it will be best to switch to Spring 2.5.2 as many bugs have been fixed since Spring 2.0.7.

                  -Ramnivas

                  Comment


                  • #11
                    Thanks!
                    I use aspectjweaver 1.5.4 and Spring 2.5.2.
                    My server-application still gets the same Exception (Pointcut not found). It's the code above.
                    Do you have any other solution?
                    AspectJWeaver 1.5.4 is the latest version in maven-repos, so it shouldn't be a version problem. The 2 other pointcuts are working fine!

                    Edit: I am using Tomcat 5.5 for my server-application. shall I use Tomcat 6.0 ?
                    Last edited by sutcha; Apr 2nd, 2008, 09:09 AM.

                    Comment


                    • #12
                      I only have the PointcutException in my server-application:

                      Code:
                      @Pointcut("execution(public void refresh()) && within(de.xy.remote.service..*)")
                      public void refreshables() {}
                      
                      @AfterThrowing(pointcut="refreshables()", throwing="t")
                      public void handle(JoinPoint jp, final Throwable t) {
                      Log log = LogFactory.getLog(jp.getTarget().getClass());
                      log.error("Caught Exception with AOP on Thread: "
                      + Thread.currentThread().getName()+" Exception: ", t);
                      exceptionReporter.setThrownException(t);
                      }
                      my other poincuts are working fine with Java 6 now I use AspecJweaver 1.5.4 and Spring 2.5.2.

                      Is there anything wrong in my code? I really need help on that thing!

                      Thanks!

                      Comment

                      Working...
                      X