简体   繁体   English

我如何手动触发另一个类的方法周围的操作

[英]how i can trigger aop around method from another class manually

i have this configuration in application xml 我在应用程序xml中有此配置

<aop:config>
    <aop:aspect id="ruleAspect" ref="ruleInterceptor">
        <aop:pointcut expression="@within(....)" id="servicePointcut" />
        <aop:around pointcut-ref="servicePointcut" method="intercept"/>
    </aop:aspect>
</aop:config>

and if user trigger any action related my rules, that code runs 如果用户触发与我的规则相关的任何操作,则该代码将运行

public Object intercept(ProceedingJoinPoint pjp) throws Throwable  {
    ...
    ...
    for (Rule rule :ruleList) {
       rule.doApply(pjp);
    }
}

and this code call rule class doApply method 和此代码调用规则类的doApply方法

public class Rule1 {

    @Override
    protected Object doApply(ProceedingJoinPoint invocation) {
        ...
        ...
    }

}

now, my question is that how can i trigger doApply method from another class manually with pjp parameter. 现在,我的问题是如何使用pjp参数手动触发另一个类的doApply方法。 i do not create pjp object because it is interface. 我不创建pjp对象,因为它是接口。 is there anyway to call it? 反正有电话吗?

I dont think that this is how you should think of aspects. 我不认为这是您应该考虑的方面。 they get invoked by the runtime and aren't meant to be manually callable. 它们在运行时被调用,并不意味着可以手动调用。

Best dont even think of aspects as classes and methods at all. 最好不要将方面完全视为类和方法。


what I would do to 'workaround this' is put the relevant logic from the aspect method into a static helper class method that you can then share between aop and manual invocation 我要做的“变通办法”是将Aspect方法中的相关逻辑放入静态助手类方法中,然后可以在aop和手动调用之间共享

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM