AspectJ 与 JSF1.2

发布于 2024-12-10 08:23:21 字数 901 浏览 3 评论 0原文

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

I am using JSF1.2 framework. I didnt Integrate my application with Spring.I want to perform profiling on method invocations. my application file is EAR (EJB + WAR ). i can get the session beans methods execution time with the help of interceptor but for WAR module i was suggested to use AspectJ in this blog. so i have written some code. is there any thing i need to do like configuration details. I added the required jar file of AspectJ is JSF support AspectJ with any configuration? my code is:

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;
 }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

把人绕傻吧 2024-12-17 08:23:21

我在 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>

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

I have created a target in WAR build.xml file and I added the AspectJ jar files. Now I am getting all the invoked methods. here is the targer code:

 <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>

put the above code in one package and add the above ant script in you war build.xml thats it it will work

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文