我有以下方法
@AutoHandling(slot = FunctionalArea.PRE_MAIN_MENU)
@RequestMapping(method = RequestMethod.GET)
public String navigation(ModelMap model) {
logger.debug("navigation");
...
//First time to the Main Menu and ID-Level is ID-1 or greater
if (!callSession.getCallFlowData().isMainMenuPlayed()
&& callSession.getCallFlowData().getIdLevel() >= 1) {
// Call Auto Handling
logger.info("Call AutoHandling");
autoHandlingComponent.processAutoHandling();
}
...
return forward(returnView);
}
基本上我想做的是在 processAutoHandling() 上有一个切入点 但在@After中,我需要使用@AutoHandling的slot()
我尝试了这个,但它没有被调用
@Pointcut("execution(* *.processAutoHandling())")
public void processAutoHandleCall() {
logger.debug("processAutoHandleCall");
}
@Around("processAutoHandleCall() &&" +
"@annotation(autoHandling) &&" +
"target(bean) "
)
public Object processAutoHandlingCall(ProceedingJoinPoint jp,
AutoHandling autoHandling,
Object bean)
throws Throwable {
...
最佳答案
您可以使用虫洞设计模式来实现此目的。我正在说明使用基于 AspectJ 字节码的方法和语法,但如果您使用 Spring 的基于代理的 AOP,您应该能够使用显式 ThreadLocal 获得相同的效果。
pointcut navigation(AutoHandling handling) : execution(* navigation(..))
&& @annotation(handling);
// Collect whatever other context you need
pointcut processAutoHandleCall() : execution(* *.processAutoHandling());
pointcut wormhole(AutoHandling handling) : processAutoHandleCall()
&& cflow(navigation(handling));
after(AutoHandling handling) : wormhole(hanlding) {
... you advice code
... access the slot using handling.slot()
}
关于java - 需要帮助创建利用方法注释中的值的特定切入点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4759803/