1

我正在使用JSF1.2框架。我没有将我的应用程序与 Spring 集成。我想对方法调用执行分析。我的应用程序文件是EAR (EJB + WAR)。我可以在拦截器的帮助下获取会话 bean 方法的执行时间,但对于 WAR 模块,我建议在此博客中使用 AspectJ。所以我写了一些代码。有什么我需要做的,比如配置细节我添加了AspectJ所需的 jar 文件,JSF 是否支持 AspectJ的任何配置?我的代码是:

import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
@Aspect
public class AopInterceptor implements MethodInterceptor{

public AopInterceptor() {
}

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

@Around("profile()")
public Object invoke(MethodInvocation mi) throws Throwable {
    System.out.println("test start");
    Object obj=mi.proceed();
    System.out.println("test end");
    return obj;
 }
}
4

1 回答 1

0

我在 WAR build.xml 文件中创建了一个目标,并添加了 AspectJ jar 文件。现在我得到了所有调用的方法。这是目标代码:

 <taskdef  classpath="C:/Users/s.kosna/Downloads/aspectj-1.6.11/lib/aspectjtools.jar"
 resource="org/aspectj/tools/ant/taskdefs/aspectjTaskdefs.properties"/>
<target name="aspectj">
<echo level="info">--- aspectj (start) ---</echo>
<condition property="targetos" value="windows" else="unix">
    <os family="windows"/>
</condition>
<pathconvert targetos="${targetos}" property="javac.convertedClasspath" >
    <path path="${javac.classpath}" />
</pathconvert>
<iajc source="1.6" target="1.6" showweaveinfo="true" verbose="true" destdir="${build.classes.dir}"  >
    <inpath>
        <pathelement location="${build.classes.dir}"/>
    </inpath>
    <classpath>
        <pathelement location="${javac.convertedClasspath}" />
    </classpath>
</iajc>
<echo level="info">LORDDOSKIAS BRUTAL TEST ---</echo>
</target>

<target name="-post-compile" depends="aspectj"></target>

将上面的代码放在一个包中,然后在你的 war build.xml 中添加上面的 ant 脚本,这样它就可以工作了

于 2011-10-21T09:22:18.123 回答