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

  • LTW + Spring

    Hi, I'm trying to use Load-Time Weaving with spring but I just can't get it to work.

    this is my META-INF/aop.xml file:

    <aspectj>

    <weaver>

    <!-- only weave the following classes -->
    <include within="ar.mycompany.cda..*"/>

    </weaver>

    <aspects>

    <!-- weave in just this aspect -->
    <aspect name="ar.mycompany.cda.aop.LoadTimeWeaving"/>

    </aspects>
    </aspectj>

    this is my aspect:

    package ar.mycompany.cda.aop;

    import org.apache.log4j.Logger;
    import org.aspectj.lang.JoinPoint;
    import org.aspectj.lang.annotation.After;
    import org.aspectj.lang.annotation.Aspect;
    import org.aspectj.lang.annotation.Before;
    import org.aspectj.lang.annotation.Pointcut;

    @Aspect
    public class LoadTimeWeaving {

    Logger logger;

    @Before("loggeoCDA()")
    public void logBefore(JoinPoint jp){
    logger = Logger.getLogger(jp.getTarget().getClass());
    logger.debug("INICIO: " + obtenerFirmaCompleta(jp));
    }

    @After("loggeoCDA()")
    public void logAfter(JoinPoint jp){
    logger = Logger.getLogger(jp.getTarget().getClass());
    logger.debug("FIN: " + obtenerFirmaCompleta(jp));
    }

    @Pointcut("execution(* ar.mycompany.cda..*.*(..))")
    public void loggeoCDA(){}

    private String obtenerFirmaCompleta(JoinPoint jpoint){
    StringBuffer buffer = new StringBuffer();
    buffer.append(jpoint.getTarget().getClass().getSim pleName() + "." + jpoint.getSignature().getName() + "(");

    Object[] args = jpoint.getArgs();
    for (int i = 0; i < args.length; i++) {
    Object arg = args[i];
    buffer.append(arg.getClass().getSimpleName()+" arg"+i);
    if (i+1<args.length){
    buffer.append(", ");
    }
    }
    buffer.append(")");
    return buffer.toString();
    }
    }

    and finally this is my spring-beans.xml config:

    <?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:aop="http://www.springframework.org/schema/aop"
    xmlns="http://www.springframework.org/schema/p"
    xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
    http://www.springframework.org/schem...-beans-2.5.xsd
    http://www.springframework.org/schema/aop
    http://www.springframework.org/schem...ng-aop-2.0.xsd
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd"
    default-autowire="byName">

    <import resource="spring-persistence.xml"/>
    <import resource="spring-dao.xml"/>
    <import resource="spring-service.xml"/>
    <import resource="spring-view.xml"/>

    <!-- ******************* LTW ******************* -->
    <context:load-time-weaver/>
    <bean name="loadTimeWeaving" class="ar.mycompany.cda.aop.LoadTimeWeaving" scope="prototype"/>
    <!-- ******************* LTW ******************* -->


    <!-- ****************** BEANS ******************-->
    <bean name="recurso" class="ar.mycompany.cda.modelo.beans.Recurso" scope="prototype"/>
    <bean name="distribucion" class="ar.mycompany.cda.modelo.beans.Distribucion" scope="prototype"/>
    <bean name="incurrido" class="ar.mycompany.cda.modelo.beans.Incurrido" scope="prototype"/>
    <bean name="asignacion" class="ar.mycompany.cda.modelo.beans.Asignacion" scope="prototype"/>
    <bean name="tareaEstimador" class="ar.mycompany.cda.modelo.beans.TareaEstimado r" scope="prototype"/>
    <bean name="tarea" class="ar.mycompany.cda.modelo.beans.Tarea" scope="prototype"/>
    <bean name="peticion" class="ar.mycompany.cda.modelo.beans.Peticion" scope="prototype"/>
    <bean name="proyecto" class="ar.mycompany.cda.modelo.beans.Proyecto" scope="prototype"/>
    <bean name="tecnologia" class="ar.mycompany.cda.modelo.beans.Tecnologia" scope="prototype"/>



    </beans>

    I'm setting the -javaagent:C:/Spring-Agent/spring-agent.jar as a VM parameter. The app runs as if nothing happened. I know the <context:load-time-weaver/> tag is being noticed because if i don't specify the -javaagent param for the VM I get an exception.

    Did I miss something configuring LTW? I'm using JAVA 5.
    Last edited by joni.loky; May 12th, 2008, 10:58 AM.

  • #2
    FIXED IT!.....THE F****** META-INF folder needed to be in my src/main/java folder. I had it at the same level as src.

    Comment


    • #3
      LTW +Spring

      Hello all,
      I have the same problem now with LTW.
      I’m having the exception “org.aspectj.lang.NoAspectBoundException”



      My aop.xml:
      <aspectj>

      <weaver>

      <!-- only weave the following classes -->
      <include within="com.my.app..*"/>

      </weaver>

      <aspects>

      <!-- weave in just this aspect -->
      <aspect name="com.my.app.aop.logging.LoggingService"/>

      </aspects>
      </aspectj>



      My Aspect:
      package com.my.app.aop.logging;

      import org.apache.commons.logging.Log;
      import org.apache.commons.logging.LogFactory;
      import org.aspectj.lang.JoinPoint;
      import org.aspectj.lang.annotation.AfterReturning;
      import org.aspectj.lang.annotation.AfterThrowing;
      import org.aspectj.lang.annotation.Aspect;
      import org.aspectj.lang.annotation.Before;
      import org.aspectj.lang.annotation.Pointcut;

      /**
      * Logging Aspect
      */
      @Aspect
      public class LoggingService {
      private static Log log = LogFactory.getLog(LoggingService.class

      @AfterReturning(value = "namegenerator()", returning = "retVal")
      public void afterReturning(final Object retVal) throws Throwable {
      log.info("After returning Advice runing");

      }

      @AfterThrowing(pointcut = "namegenerator()", throwing = "exception")
      public void afterThrowing(final JoinPoint jp, final Throwable exception) {
      log.error("Exception:" + exception.getStackTrace(), exception);
      }

      @Before("namegenerator()")
      public void before(JoinPoint jp) throws Throwable {
      log.info("Before Advice runing ");
      }

      @Pointcut(value = "within(de.hhla.tzs..*)", argNames = "s,o")
      public void namegenerator() {
      }

      }

      Context 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"
      xsi:schemaLocation="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:load-time-weaver/>
      <bean id="loggingService" class="com.my.app.aop.logging.LoggingService" scope="prototype"/>

      <bean id="generator" class="com.my.app.GeneratorFichier">
      </bean>
      </beans>

      I can’t figure out what I’m doing wrong. As stated I’m getting the Exception:

      “org.aspectj.lang.NoAspectBoundException: com.my.app.aop.logging.LoggingService”

      Please help,

      djemgo

      Comment


      • #4
        You are using loadtimeweaving, so don't specify your aspect in the applicationContext.xml file.

        Also use [ code][/code ] tags when posting code!!!!

        Comment


        • #5
          THNX...actually it was left overs from when I was trying to use CGLIB proxys

          Comment


          • #6
            Originally posted by joni.loky View Post
            FIXED IT!.....THE F****** META-INF folder needed to be in my src/main/java folder. I had it at the same level as src.
            I suppose you're using Maven2, in which case you should put the META-INF folder under src/main/resources with all other resource files; src/main/java should only contain Java source files. The final JAR / WAR artifact will be the same.

            Cheers,
            GB

            Comment


            • #7
              Thanks spiff. Hey, is there a way to specify a different folder for my aop.xml file?

              Comment


              • #8
                Hey, is there a way to specify a different folder for my aop.xml file?
                You can use the org.aspectj.weaver.loadtime.configuration system property to specify the path of the load-time weaving configuration files that are read. For example: -Dorg.aspectj.weaver.loadtime.configuration=META-INF/aop1.xml;META-INF/aop2.xml

                Cheers,
                GB

                Comment


                • #9
                  Hallo Marten,
                  thanks a lot for your email.
                  I've changed my ContextFile according to your email. Ijust removed the declaration of my Aspect bean. I'm still getting exactly the same Exception
                  I guess there’s another problem somewhere else.
                  Any help would be welcome.
                  Djemgo

                  Comment


                  • #10
                    Where should I set that? I tried setting it as a VM parameter in eclipse when I start my tomcat server but nothing happens.

                    Comment

                    Working...
                    X