Aspectj Without Spring

这篇博客介绍了如何在不依赖Spring的情况下安装并使用AspectJ。首先,跟随给出的链接完成安装和HelloWorld示例。接着,重点讨论了源代码的查看和反编译,建议使用JD-GUI而非IDEA内置的反编译工具,因为JD-GUI能提供更清晰的反编译结果。最后,列出了AppAspect和App两个关键类。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Install and HelloWorld

Follow this
http://zhoujingxian.iteye.com/blog/667214
在这里插入图片描述

Src

App.java

aspect AppAspect {
    void around():call(void App.sayHello()){
        System.out.println("before transaction....");
        proceed();
        System.out.println("after transaction....");
    }
}
public class App 
{
    public void sayHello(){
        System.out.println("Hello AspectJ.");
    }
    public static void main( String[] args )
    {
        App app = new App();
        app.sayHello();
    }
}

Decompile

decompile 千万不要用idea原生的,反编译出来跟源代码没啥区别,要用JD-GUI http://jd.benow.ca/

AppAspect.class

import org.aspectj.runtime.internal.AroundClosure;

public class AppAspect {
    public static AppAspect aspectOf() {
        if (ajc$perSingletonInstance == null)
            throw new org.aspectj.lang.NoAspectBoundException("AppAspect", ajc$initFailureCause);
        return ajc$perSingletonInstance;
    }

    public static boolean hasAspect() {
        return ajc$perSingletonInstance != null;
    }

    private static void ajc$postClinit() {
        ajc$perSingletonInstance = new AppAspect();
    }

    static {
        try {
        } catch (Throwable localThrowable) {
            ajc$initFailureCause = localThrowable;
        }
    }

    public void ajc$around$AppAspect$1$9ee7cbd2(AroundClosure ajc$aroundClosure) {
        System.out.println("before transaction....");
        ajc$around$AppAspect$1$9ee7cbd2proceed(ajc$aroundClosure);
        System.out.println("after transaction....");
    }

    private static Throwable ajc$initFailureCause;
    public static AppAspect ajc$perSingletonInstance;

    AppAspect() {
    }

    static void ajc$around$AppAspect$1$9ee7cbd2proceed(AroundClosure this)
            throws Throwable {
    }
}

App.class

import org.aspectj.runtime.internal.AroundClosure;

public class App {
    private static final void sayHello_aroundBody1$advice(App target, AppAspect ajc$aspectInstance, AroundClosure ajc$aroundClosure) {
        System.out.println("before transaction....");
        AroundClosure localAroundClosure = ajc$aroundClosure;
        sayHello_aroundBody0(target);
        System.out.println("after transaction....");
    }


    public void sayHello() {
        System.out.println("Hello AspectJ.");
    }

    public static void main(String[] args) {
        App app = new App();
        App localApp1 = app;
        sayHello_aroundBody1$advice(localApp1, AppAspect.aspectOf(), null);
    }

    private static final void sayHello_aroundBody0(App paramApp) {
        paramApp.sayHello();
    }

    public App() {
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值