[英]AspectJ with JSF1.2
我正在使用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;
}
}
我在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腳本,這樣就可以了
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.