Announcement Announcement Module
Collapse
No announcement yet.
AspectJ AOP not working Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • AspectJ AOP not working

    I created the advice class

    @Aspect
    public class DAOUpdateEventAspect {

    @Before("execution(* createParty(..))")
    public void logBefore(JoinPoint joinPoint) {
    System.out.println("Method signatue " + joinPoint.getSignature().toString());


    }

    }

    my pointcut method classes are as follows


    public interface AbcDAO extends DAO {

    PartyDABImpl createParty(PartyDABImpl partyDAB);
    }

    @DAO
    public class AbcDAOImpl implements ApplicationPartyDAO {

    public PartyDABImpl createParty(PartyDABImpl partyDAB) {
    System.out.println("creating party");
    createOrUpdateParty(partyDAB);
    return partyDAB;
    }
    }

    included dependency jar file (aopalliance-1.0.jar,asm-all-3.3.1.jar,aspectjrt.jar,aspectjweaver.jar,commons-logging-1.1.jar) and all spring framework libs


    following is my xml file

    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:jdbc="http://www.springframework.org/schema/jdbc"
    xmlns:aop="http://www.springframework.org/schema/aop"
    xsi:schemaLocation="http://www.springframework.org/schema/jdbc http://www.springframework.org/schem...pring-jdbc.xsd
    http://www.springframework.org/schema/aop http://www.springframework.org/schem...ng-aop-3.0.xsd
    http://www.springframework.org/schema/beans http://www.springframework.org/schem...-beans-2.5.xsd
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd">


    <context:annotation-config />

    <!--
    | DAOs
    +-->

    <context:component-scan base-package="au.com.xx.yy">
    <context:include-filter type="annotation" expression="org.springframework.stereotype.Compone nt" />
    <context:include-filter type="annotation" expression="com.xx.yy.core.annotations.DAO" />

    </context:component-scan>
    <aop:aspectj-autoproxy />
    <bean id="daoUpdateEventListener"
    class="au.com.xx.yy.utils.dao.DAOUpdateEventAspect " />


    </beans>

    for some reason the advise method is never called. Is there something wrong or is there a way to debug AOP to look into the proxy object, etc ?

    Any help would be greatly be appreciated

  • #2
    Please use [ code][/code ] tags when posting code/xml/stacktraces that way it remains readable ..

    1. Make sure you are using the proxied instance and not creating new instances of your dao yourself
    2. YOu use component-scanning make sure you only scan for components in the context that has tha aop defined else you have 2 bean instances 1 proxied one not proxied.

    Comment


    • #3
      HI,
      you have to use @Before("execution(* *.createParty(..))") instead of @Before("execution(* createParty(..))")

      Comment

      Working...
      X