Jar 让LTW在Web应用程序中工作的诀窍是什么?

Jar 让LTW在Web应用程序中工作的诀窍是什么?,jar,war,aspectj,load-time,Jar,War,Aspectj,Load Time,我希望能够在加载时使用Spring和AspectJ将一个方面编织到现有的tomcat webapp中。我使用AspectJ是因为我需要执行构造函数切入点。 我有两个测试场景,其中我的方面是一个简单servlet应用程序的一部分——应用程序包含方面的源代码,我使用MVN和aspectJ插件编译WAR和方面。这方面的工作与预期一样。第二种情况是,我将方面分离到自己的项目中,并使用(我已经尝试了AJC和AJDT)将其编译成一个JAR文件,并将JAR文件包含在我的war/WEB-INF/lib文件夹中。

我希望能够在加载时使用Spring和AspectJ将一个方面编织到现有的tomcat webapp中。我使用AspectJ是因为我需要执行构造函数切入点。
我有两个测试场景,其中我的方面是一个简单servlet应用程序的一部分——应用程序包含方面的源代码,我使用MVN和aspectJ插件编译WAR和方面。这方面的工作与预期一样。第二种情况是,我将方面分离到自己的项目中,并使用(我已经尝试了AJC和AJDT)将其编译成一个JAR文件,并将JAR文件包含在我的war/WEB-INF/lib文件夹中。在加载war文件上下文时,似乎正在拾取方面,但未将其应用于war文件中的任何对象

以下是方面代码:

@SuppressWarnings("unused")
public aspect ProjectMonitor{

    pointcut constr() :  call(com.avaya..*.new(..)) ;
    Object around() : constr(){
        System.out.println("In Constructor for "
                + thisJoinPointStaticPart.getSignature());
        Object ret = proceed();
        return ret;
    }

    pointcut publicOperation() : execution(public * *.*(..));
    Object around() : publicOperation() {
        long start = System.nanoTime();
        Object ret = proceed();
        long end = System.nanoTime();
        System.out.println(thisJoinPointStaticPart.getSignature() + " took "
                + (end - start) + " nanoseconds");
        return ret;
    }

    pointcut callConst() : call(public *..*SCESession.new(..));
    public Object callConst(ProceedingJoinPoint jp) throws Throwable {
        System.out.println("In Project Monitor!!!");
        return jp.proceed();
    }


}
我在web app/META-INF文件夹中包含了一个aop.xml文件:

<aspectj>
    <aspects>
        <aspect name="com.ddvc.ivr.ProjectMonitor" />
    </aspects>
</aspectj>

当源代码是用WAR文件编译的,但当它作为JAR文件包含在类路径中时,它根本不起作用

在重新加载WAR上下文文件时,我多次在tomcat日志文件中看到以下内容:

11:27:51285调试GenericTypeResolver:151-解析的返回类型 [公共静态 org.springframework.beans.factory.aspectj.annotationBeanConfigureScope org.springframework.beans.factory.aspectj.annotationBeanConfigureSpect.aspectOf()] 使用具体的方法参数[{}]

欢迎回复!提前感谢,,
格里夫

愚蠢的错误需要时间和金钱。我在WAR文件/META-INF文件夹中包含aop.xml,而不是包含的JAR文件。将aop.xml文件移到JAR文件中修复了这个问题

<?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:tx="http://www.springframework.org/schema/tx"
       xmlns:p="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/schema/beans/spring-beans-3.0.xsd
       http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
       http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
       http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">


    <context:load-time-weaver aspectj-weaving="on" />
    <context:spring-configured />
    <context:component-scan base-package="com.avaya.sce.runtimecommon"/>
    <context:annotation-config />
    <aop:aspectj-autoproxy />

    <!-- Aspect Mapping -->

    <bean id="monitor" class="com.ddvc.ivr.ProjectMonitor" factory-method="aspectOf"/>

</beans>
export JAVA_OPTS="-Xmx1024M -Xms1024M -server -javaagent:/software/apache-tomcat-6.0.36/lib/spring-instrument-3.2.1.RELEASE.jar"