Java AspectJ:两种教程
根据我的研究,我知道有两种使用AspectJ的方法。首先是创建Java AspectJ:两种教程,java,aspectj,Java,Aspectj,根据我的研究,我知道有两种使用AspectJ的方法。首先是创建A.aj类,其次是在A.java中添加注释@Aspect 我正在寻找第二类的好教程,特别是关于像 @After("call(void fooMethod())") @Around("call(void sendAndReceive())") @Before("execution(String greeting(..)) && args(context)") 但我不知道他们是怎么称呼的 你能推荐一些教程吗?这种风
A.aj
类,其次是在A.java
中添加注释@Aspect
我正在寻找第二类的好教程,特别是关于像
@After("call(void fooMethod())")
@Around("call(void sendAndReceive())")
@Before("execution(String greeting(..)) && args(context)")
但我不知道他们是怎么称呼的
你能推荐一些教程吗?这种风格被称为@AspectJ,以强调注释的作用。查看和。注释和XML方式: 注释方式: 最小xml配置文件:
XML方式:
最小XML配置:
不需要更改代码
预请求:
aop名称空间必须存在于XML文件中注意使用AspectJ的人的利益,但不熟悉Spring——Vikram在这里的回答是如何在Spring的配置文件中配置方面。此外,他还提供了第三种定义方面的方法——通过XML配置文件。当您直接在AspectJ而不是Spring中编程时,AspectJ配置文件(通常称为“aop.xml”)中也提供了类似的功能。不幸的是,这并没有解决最初的问题。
<!-- Enable autoproxy to pick up all Java files tagged as @Aspect behave like Aspects -->
<aspectj-autoproxy/>
<!-- define bean -->
<!-- Note: MyUselessAspect.java should exist and this class must be tagged as @Aspect -->
<bean id="myUselessAspect" class="...MyUselessAspect" />
<aop:config>
<aop:aspect ref="myUselessAspect">
<!-- this point-cut picks all methods of any return type, from any package/class with any number of Parameters -->
<aop:before method="doSomethingBeforeMethodCall" pointcut="execution(* *.*(..))"/>
<aop:after method="doSomethingAfterMethodCall" pointcut="execution(* *.*(..))"/>
</aop:aspect>
</aop:config>
<!-- No need to Annotate this java Class as @Aspect. Neither you need to define any
Point-cuts or Advices in the Java file. The <aop:config> tag takes care of everything -->
<bean id="myUselessAspect" class="...MyUselessAspect"></bean>