Results 1 to 8 of 8

Thread: Advice not getting called

  1. #1
    Join Date
    Oct 2007
    Posts
    1

    Angry Advice not getting called

    Hi,

    I am having problems with a very simple advice which is not getting called at all.

    I am using annotations and have two mettods in the class (annotated @Aspect) with defined as follows:

    Code:
    @Pointcut("execution(public * *(..))")
    public void dbProcessPointCut()
    {
    }
    Code:
    @Around("dbProcessPointCut()")
    public Object dbProcessAdvice(ProceedingJoinPoint joinPoint) throws Throwable
    {
        LOG.debug("EXECUTING " + joinPoint.getSignature());
        Object o = joinPoint.proceed();
        LOG.debug("RETURNING " + joinPoint.getSignature());
        return o;
    }
    In our Spring config I have tried both the following:

    Code:
    <aop:aspectj-autoproxy/>
    Code:
    <aop:aspectj-autoproxy proxy-target-class="true"/>
    Once the web-app is running the advice is just not getting called, if I debug the app a break point on my advice is never hit and it seems that the class is not even created. This advice is in a web-app with JPA/Hibernat/Transactional integration and they all seem to be working fine.

    Any advice anyone can offer is much appreciated.

    Regards,

    Chris.

  2. #2

    Default

    You need to register the @Aspect class as a bean in the context.

  3. #3
    Join Date
    Dec 2006
    Posts
    8

    Red face I have similar problem, and my @Aspect class is defined in bean.

    I have the exact same problem, even though I have the @Aspect class declared ni the Spring XML file. The aspect below should intercept all my Spring MVC form controllers' onSubmit() method. I put a break point and ran in debug mode, and it never reaches the aspect.

    I have listed below relevent parts of Spring XML file, pom jar dependencies, and a simple form controller.

    I am guessing there is some missing library. Any help would be greatly appreciate


    Thanks in advance,

    Eliot Clingman (Foaming at mouth, biting on carpet, etc.)


    @Aspect
    public class AuditAspect {

    @Pointcut("execution(* *.onSubmit(..))")
    public void onSubmit() {
    }

    @AfterReturning("onSubmit()")
    public void updateAudit() {
    System.out.print("Updating the audit!");
    // TODO save audit trail in database for real
    }
    }

    I have declared it in my spring XML file:

    <bean id="auditAspect"
    class="com.qualcomm.crowd.aspect.AuditAspect" />
    <aop:aspectj-autoproxy/>

    I declare the following libraries in my Maven 2 POM file:

    <!-- Spring libraries -->
    <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-core</artifactId>
    <version>2.0.7</version>
    <scope>compile</scope>
    <type>jar</type>
    </dependency>
    <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-beans</artifactId>
    <version>2.0.7</version>
    <scope>compile</scope>
    <type>jar</type>
    </dependency>
    <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-web</artifactId>
    <version>2.0.7</version>
    <scope>compile</scope>
    <type>jar</type>
    </dependency>
    <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-webmvc</artifactId>
    <version>2.0.7</version>
    <scope>compile</scope>
    <type>jar</type>
    </dependency>
    <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-mock</artifactId>
    <version>2.0.7</version>
    <scope>compile</scope>
    <type>jar</type>
    </dependency>
    <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-aop</artifactId>
    <version>2.0.7</version>
    <scope>compile</scope>
    <type>jar</type>
    </dependency>
    <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-support</artifactId>
    <version>2.0.7</version>
    <scope>compile</scope>
    <type>jar</type>
    </dependency>
    <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-remoting</artifactId>
    <version>2.0.7</version>
    <scope>compile</scope>
    <type>jar</type>
    </dependency>
    <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-aspects</artifactId>
    <version>2.0.7</version>
    <scope>compile</scope>
    <type>jar</type>
    </dependency>
    <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-ldap</artifactId>
    <version>1.1.2</version>
    <scope>compile</scope>
    <type>jar</type>
    </dependency>
    <dependency>
    <groupId>aspectj</groupId>
    <artifactId>aspectjlib</artifactId>
    <version>1.5.3</version>
    <scope>compile</scope>
    <type>jar</type>

    </dependency>


    ... also, here is one of the form controllers that is being ignored:

    public class WirelessDeviceGeneralInfoFormController extends SimpleFormController {

    ....
    .....
    protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object command,
    BindException errors) throws NoSuchWirelessDeviceException, Exception {
    WirelessDevice wirelessDevice = (WirelessDevice) command;
    if (wirelessDevice.getId() == 0) {
    this.wirelessDeviceManager.save(wirelessDevice);
    } else {
    this.wirelessDeviceManager.update(wirelessDevice);
    }
    return new ModelAndView(getSuccessView(), "wirelessDevice", wirelessDevice);
    }
    }

  4. #4
    Join Date
    Sep 2007
    Location
    Oceanside, CA
    Posts
    187

    Default

    Eliot -

    Since Spring AOP relies on interception, the only method call which can be advised in the Controller hierarchy is AbstractController.handleRequest(). Other method calls, such the the call to onSubmit() that you are attempting to advise, are called internally by the framework, and will not be intercepted.

    Using AspectJ might be an alternative if you need more flexibility. See here for additional discussion:

    http://forum.springframework.org/showthread.php?t=35012
    Mike Bingham

  5. #5
    Join Date
    Dec 2006
    Posts
    8

    Default @AspectJ and accessing args

    Hi Mike,

    Your suggestion worked, thanks!

    However, after I successfully intercepted the handleRequest() method based on your directions, I next tried to modify my aspect to get a handle on the httpServletRequest argument of handleRequest():

    @Aspect
    public class AuditAspect {

    @Pointcut("execution(* *.handleRequest(..)) && args(request)")
    public void handleRequest() {
    }

    @AfterReturning("handleRequest()")
    public void audit(HttpServletRequest request) {
    System.out.println(request.toString());
    System.out.println("Updating the audit Trail. Yippie!");
    // TODO update audit trail in database
    }
    }

    However, I guess I have the syntax wrong because the args thing fails, and this is the resulting error message:


    java.lang.IllegalArgumentException: warning no match for this type name: request [Xlint:invalidAbsoluteTypeName]
    at org.aspectj.weaver.tools.PointcutParser.parsePoint cutExpression(PointcutParser.java:315)
    at org.springframework.aop.aspectj.AspectJExpressionP ointcut.buildPointcutExpression(AspectJExpressionP ointcut.java:189)
    at org.springframework.aop.aspectj.AspectJExpressionP ointcut.checkReadyToMatch(AspectJExpressionPointcu t.java:176)
    at org.springframework.aop.aspectj.AspectJExpressionP ointcut.getClassFilter(AspectJExpressionPointcut.j ava:157)
    at org.springframework.aop.support.AopUtils.canApply( AopUtils.java:189)
    at org.springframework.aop.support.AopUtils.canApply( AopUtils.java:244)
    at org.springframework.aop.support.AopUtils.findAdvis orsThatCanApply(AopUtils.java:278)
    at org.springframework.aop.framework.autoproxy.Abstra ctAdvisorAutoProxyCreator.findEligibleAdvisors(Abs tractAdvisorAutoProxyCreator.java:83)
    at org.springframework.aop.framework.autoproxy.Abstra ctAdvisorAutoProxyCreator.getAdvicesAndAdvisorsFor Bean(AbstractAdvisorAutoProxyCreator.java:66)
    at org.springframework.aop.framework.autoproxy.Abstra ctAutoProxyCreator.postProcessAfterInitialization( AbstractAutoProxyCreator.java:296)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.applyBeanPostProcessors AfterInitialization(AbstractAutowireCapableBeanFac tory.java:313)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.initializeBean(Abstract AutowireCapableBeanFactory.java:1176)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean(AbstractAuto wireCapableBeanFactory.java:427)
    at org.springframework.beans.factory.support.Abstract BeanFactory$1.getObject(AbstractBeanFactory.java:2 49)
    at org.springframework.beans.factory.support.DefaultS ingletonBeanRegistry.getSingleton(DefaultSingleton BeanRegistry.java:155)
    at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:246)
    .....
    .....

    By the way, below are my current libraries.

    Thanks,

    Eliot

    <dependencies>

    <!-- AspectJ Libraries -->
    <dependency>
    <groupId>asm</groupId>
    <artifactId>asm-attrs</artifactId>
    <version>2.2.3</version>
    <scope>compile</scope>
    <type>jar</type>
    </dependency>
    <dependency>
    <groupId>aspectj</groupId>
    <artifactId>aspectjrt</artifactId>
    <version>1.5.3</version>
    <scope>compile</scope>
    <type>jar</type>
    </dependency>
    <dependency>
    <groupId>aspectj</groupId>
    <artifactId>aspectjweaver</artifactId>
    <version>1.5.3</version>
    <scope>compile</scope>
    <type>jar</type>
    </dependency>
    <dependency>
    <groupId>aspectj</groupId>
    <artifactId>aspectjlib</artifactId>
    <version>1.5.3</version>
    <scope>compile</scope>
    <type>jar</type>
    </dependency>
    <dependency>
    <groupId>asm</groupId>
    <artifactId>asm</artifactId>
    <version>2.2.3</version>
    <scope>compile</scope>
    <type>jar</type>
    </dependency>
    <dependency>
    <groupId>asm</groupId>
    <artifactId>asm-commons</artifactId>
    <version>2.2.3</version>
    <scope>compile</scope>
    <type>jar</type>
    </dependency>
    <dependency>
    <groupId>asm</groupId>
    <artifactId>asm-tree</artifactId>
    <version>2.2.3</version>
    <scope>compile</scope>
    <type>jar</type>
    </dependency>







    <!-- Spring libraries -->
    <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-core</artifactId>
    <version>2.0.7</version>
    <scope>compile</scope>
    <type>jar</type>
    </dependency>
    <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-beans</artifactId>
    <version>2.0.7</version>
    <scope>compile</scope>
    <type>jar</type>
    </dependency>
    <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-web</artifactId>
    <version>2.0.7</version>
    <scope>compile</scope>
    <type>jar</type>
    </dependency>
    <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-webmvc</artifactId>
    <version>2.0.7</version>
    <scope>compile</scope>
    <type>jar</type>
    </dependency>
    <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-mock</artifactId>
    <version>2.0.7</version>
    <scope>compile</scope>
    <type>jar</type>
    </dependency>
    <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-aop</artifactId>
    <version>2.0.7</version>
    <scope>compile</scope>
    <type>jar</type>
    </dependency>
    <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-support</artifactId>
    <version>2.0.7</version>
    <scope>compile</scope>
    <type>jar</type>
    </dependency>
    <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-remoting</artifactId>
    <version>2.0.7</version>
    <scope>compile</scope>
    <type>jar</type>
    </dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-aspects</artifactId>
    <version>2.0.7</version>
    <scope>compile</scope>
    <type>jar</type>
    </dependency>

    <!-- Needed for class byte code manipulation -->
    <dependency>
    <groupId>cglib</groupId>
    <artifactId>cglib-nodep</artifactId>
    <version>2.1_3</version>
    <scope>compile</scope>
    <type>jar</type>
    </dependency>

    <dependency>
    <groupId>commons-lang</groupId>
    <artifactId>commons-lang</artifactId>
    <version>2.3</version>
    <scope>compile</scope>
    <type>jar</type>
    </dependency>
    <dependency>
    <groupId>commons-collections</groupId>
    <artifactId>commons-collections</artifactId>
    <version>2.1</version>
    </dependency>
    <dependency>
    <groupId>log4j</groupId>
    <artifactId>log4j</artifactId>
    <version>1.2.14</version>
    <scope>compile</scope>
    <type>jar</type>
    </dependency>
    <dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>servlet-api</artifactId>
    <version>2.5</version>
    <scope>provided</scope>
    <type>jar</type>
    </dependency>
    <dependency>
    <groupId>commons-dbcp</groupId>
    <artifactId>commons-dbcp</artifactId>
    <version>1.2.1</version>
    <scope>compile</scope>
    <type>jar</type>
    </dependency>
    <dependency>
    <groupId>xerces</groupId>
    <artifactId>xercesImpl</artifactId>
    <version>2.8.0</version>
    <scope>compile</scope>
    <type>jar</type>
    </dependency>
    <dependency>
    <groupId>commons-discovery</groupId>
    <artifactId>commons-discovery</artifactId>
    <version>20040218.194635</version>
    </dependency>


    <!-- More common libraries -->
    <dependency>
    <groupId>org.apache.ant</groupId>
    <artifactId>ant-antlr</artifactId>
    <version>1.7.0</version>
    <scope>compile</scope>
    <type>jar</type>
    </dependency>
    <dependency>
    <groupId>commons-chain</groupId>
    <artifactId>commons-chain</artifactId>
    <version>1.1</version>
    <scope>compile</scope>
    <type>jar</type>
    </dependency>
    <dependency>
    <groupId>commons-digester</groupId>
    <artifactId>commons-digester</artifactId>
    <version>1.8</version>
    <scope>compile</scope>
    <type>jar</type>
    </dependency>
    <dependency>
    <groupId>commons-fileupload</groupId>
    <artifactId>commons-fileupload</artifactId>
    <version>1.1.1</version>
    <scope>compile</scope>
    <type>jar</type>
    </dependency>
    <dependency>
    <groupId>commons-io</groupId>
    <artifactId>commons-io</artifactId>
    <version>1.3.1</version>
    <scope>compile</scope>
    <type>jar</type>
    </dependency>
    <dependency>
    <groupId>org.apache.struts</groupId>
    <artifactId>struts-tiles</artifactId>
    <version>1.3.5</version>
    <scope>compile</scope>
    <type>jar</type>
    </dependency>
    <dependency>
    <groupId>taglibs</groupId>
    <artifactId>standard</artifactId>
    <version>1.1.2</version>
    <scope>compile</scope>
    <type>jar</type>
    </dependency>
    <dependency>
    <groupId>quartz</groupId>
    <artifactId>quartz</artifactId>
    <version>1.5.2</version>
    </dependency>
    <dependency>
    <groupId>junit</groupId>
    <artifactId>junit</artifactId>
    <version>3.8.1</version>
    <scope>test</scope>
    </dependency>
    </dependencies>

  6. #6
    Join Date
    Sep 2007
    Location
    Oceanside, CA
    Posts
    187

    Default

    It looks like you need to make a small change to your pointcut definition to include the argument as a method parameter. For example:

    Code:
    @Pointcut("execution(* *.handleRequest(..)) && args(request)")
    public void handleRequest(HttpServletRequest request) {
    }
    Also, modify your @AfterReturning annotation to include the parameter with the pointcut reference. For example:

    Code:
    @AfterReturning("handleRequest(request)")
    public void audit(HttpServletRequest request) {
    ...
    Mike Bingham

  7. #7
    Join Date
    Dec 2006
    Posts
    8

    Default

    Hi Mike,

    I tried that, but have a new error message (please see below). I guess I have a problem with jar versions.

    My previous post listed my jar dependencies. In summary my asm's are all version 2.2.3 and my aspectj's are 1.5.3. If I recall correctly I changed asm's to 2.2.3 from 1.5.3 because asm-common didn't have a 1.5.3 version
    Finally, I am on Spring 2.0.7.

    Anyway, could you suggest possible fix to my library dependencies?


    Thanks in advance,

    Eliot



    java.lang.NoClassDefFoundError: org/objectweb/asm/CodeVisitor
    at net.sf.cglib.core.KeyFactory$Generator.generateCla ss(KeyFactory.java:165)
    at net.sf.cglib.core.DefaultGeneratorStrategy.generat e(DefaultGeneratorStrategy.java:25)
    at net.sf.cglib.core.AbstractClassGenerator.create(Ab stractClassGenerator.java:216)
    at net.sf.cglib.core.KeyFactory$Generator.create(KeyF actory.java:145)
    at net.sf.cglib.core.KeyFactory.create(KeyFactory.jav a:117)
    at net.sf.cglib.core.KeyFactory.create(KeyFactory.jav a:108)
    at net.sf.cglib.core.KeyFactory.create(KeyFactory.jav a:104)
    at net.sf.cglib.proxy.Enhancer.<clinit>(Enhancer.java :69)
    at org.hibernate.proxy.pojo.cglib.CGLIBLazyInitialize r.getProxyFactory(CGLIBLazyInitializer.java:107)
    at org.hibernate.proxy.pojo.cglib.CGLIBProxyFactory.p ostInstantiate(CGLIBProxyFactory.java:43)
    at org.hibernate.tuple.entity.PojoEntityTuplizer.buil dProxyFactory(PojoEntityTuplizer.java:162)
    at org.hibernate.tuple.entity.AbstractEntityTuplizer. <init>(AbstractEntityTuplizer.java:135)

  8. #8
    Join Date
    Dec 2006
    Posts
    8

    Post I figured out library problem - hibernate version of ciglib

    Hi Mike,

    Your fix worked... thanks a million The library problem was with Hibernate using older asm version, so I exlcluded cglib from hibernate, then added clglib-nodep version 2.1_3:


    <dependency>
    <groupId>cglib</groupId>
    <artifactId>cglib-nodep</artifactId>
    <version>2.1_3</version>
    </dependency>



    Regards,

    Eliot

Posting Permissions

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