Announcement Announcement Module
Collapse
No announcement yet.
Spring + AspectJ Problem Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring + AspectJ Problem

    Hi All,

    I have the following aspect:
    @Aspect
    public class SiteAccessInterceptor {
    @Around("@annotation(com.test.SitePublisher)")
    public void handleEvent(ProceedingJoinPoint call) throws Throwable {

    }
    }

    my annotatation is defined as:
    @Documented
    @Retention(value=RetentionPolicy.RUNTIME)
    @Target(value={ElementType.METHOD})
    public @interface SitePublisher
    {

    }


    I have annotated my target class as ..
    public class MyController extends AbstractWizardFormController{

    @SitePublisher
    public Map referenceData(
    HttpServletRequest request,
    Object command,
    Errors errors,
    int page) throws Exception {

    }

    }

    my spring configuration is:

    <aop:aspectj-autoproxy/>
    <bean id="siteAccessInterceptor"
    class="com.test.SiteAccessInterceptor">
    </bean>

    <bean id="myController" class="com.test.MyController">


    When I run the program it doesnt give my any errors but the aspect never get applied to that method. Any ideas on whats going wrong??

    Regards,
    Dharshana
    Last edited by dharshanav; Jul 31st, 2007, 11:07 AM. Reason: code edit

  • #2
    Hello,

    i think your problem is that you don't call this method through an interface, hence this advice will be not executed. You should try to to enable proxyTargetClass to true, or go for "native" AspectJ.

    best regards
    agim

    Comment


    • #3
      I tried using proxy-Target-Class and it is still the same. Can you please expllain what you mean by native AspectJ, I thought the org.springframework.aop.aspectj.annotation.Annotat ionAwareAspectJAutoProxyCreator class created AspectJ translated the @Aspect annotations as proper AspectJ native Aspects

      Comment


      • #4
        Hello,

        spring by default is a proxy based aop framework. This means taht you can only advice method calls which are called through interfaces. In your case, you are not calling this method through the interface thats why the aspect is not getting fired.

        If you enable proxy-target-class to true, could you please check if you have an cglib enhanced class or not ?

        If you use AspectJ with compile-time or load-time weaving, then the method will be adviced by AspectJ itself.

        best regards
        agim

        Comment

        Working...
        X