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.


="http://www.springframework.org/schema/p"
Reply With Quote
