【问题标题】:AspectJ with JSF1.2AspectJ 与 JSF1.2
【发布时间】:2011-10-14 12:16:09
【问题描述】:

我正在使用 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;
 }
}

【问题讨论】:

  • 请不要将[closed] 放在您的问题标题中。谢谢。
  • 我在 WAR build.xml 文件中创建了一个目标,并添加了 AspectJ jar 文件。现在我得到了所有调用的方法。这是目标代码:

标签: netbeans-6.9 jsf-1.2


【解决方案1】:

我在 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脚本,这样它就可以工作了

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-09-17
    • 2010-12-09
    • 2011-05-29
    • 2021-08-01
    • 2010-11-12
    • 2013-08-23
    相关资源
    最近更新 更多