Announcement Announcement Module
No announcement yet.
Bad pointcut expression? Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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:
    public class ListDAOImpl extends HibernateDaoSupport implements ListDAO 
        public List<Decision> listLiteDecisions()
             return (List<Decision>) getHibernateTemplate().findByNamedQuery("Decision.listLiteDecisions");        
    The Spring config for the aspect is:
    <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"/>
    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:

    Caused by: org.springframework.aop.framework.AopConfigException: Could not generate CGLIB subclass of class [class]: 
    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
    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:

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

    execution(* (@org.springframework.stereotype.Repository *).*(..))
    Last edited by ramnivas; Jun 14th, 2008, 01:51 PM.