Results 1 to 2 of 2

Thread: Bad pointcut expression?

  1. #1
    Join Date
    Mar 2005
    Posts
    11

    Default Bad pointcut expression?

    I am trying to create a pointcut expression to select the methods of all beans annotated with @Repository. Here is one of the beans I am trying to capture:
    Code:
    @Repository
    public class ListDAOImpl extends HibernateDaoSupport implements ListDAO 
    {       
        @SuppressWarnings("unchecked")
        public List<Decision> listLiteDecisions()
        { 
             return (List<Decision>) getHibernateTemplate().findByNamedQuery("Decision.listLiteDecisions");        
        }    
    }
    The Spring config for the aspect is:
    Code:
    <aop:aspect id="profileAspect" ref="daoProfiler">
        <aop:pointcut id="debug" expression="@target(org.springframework.stereotype.Repository) and execution(* com.db.fir..*.*(..))"/>
        <aop:around pointcut-ref="debug" method="profile"/>
    </aop:aspect>
    For some reason, it is trying to proxy a bean that does not have this annotation on it, and its barfing because it does not have a no-args constructor:

    Code:
    Caused by: org.springframework.aop.framework.AopConfigException: Could not generate CGLIB subclass of class [class com.db.fir.bloomberg.Bloomberg]: 
    Common causes of this problem include using a final class or a non-visible class; nested exception is java.lang.IllegalArgumentException: 
    Superclass has no null constructors but no arguments were given
    When I remove the aspect config, the app deploys and runs correctly (ie, the offending bean is fine on its own). Is there something wrong with my pointcut expression? I don't believe it should be trying to proxy this other bean.

  2. #2
    Join Date
    Jun 2006
    Location
    SF Bay Area, California
    Posts
    524

    Default

    The problem is that @target() leads to join points matching based on a runtime check, hence the decision to proxy a bean is made solely on the basis of the execution(...) part of the pointcut. In your case, that means every bean from com.db.fir and its subpackages will have a proxy.

    A simple solution is to use a pointcut such as the following:

    Code:
    execution(* (@org.springframework.stereotype.Repository com.db.fir..*).*(..))
    or (if you don't need to worry about com.db.fir package):

    Code:
    execution(* (@org.springframework.stereotype.Repository *).*(..))
    -Ramnivas
    Last edited by ramnivas; Jun 14th, 2008 at 01:51 PM.
    Ramnivas Laddad (Follow me on Twitter)
    AspectJ in Action: Enterprise AOP with Spring Applications (2nd edition). Now available!

Posting Permissions

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