我有以下方法
@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中,我需要使用slot()来实现@AutoHandling
我尝试了这个,但它没有被称为
@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 {
...
答案 0 :(得分:2)
您可以使用虫洞设计模式。我使用基于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()
}
答案 1 :(得分:0)
a)它无法运作,你试图匹配两个不同的东西:
@Around("processAutoHandleCall() &&" +
"@annotation(autoHandling) &&" +
"target(bean) "
)
processHandleCall()
匹配内部方法执行autoHandlingComponent.processAutoHandling()
,而@annotation(autoHandling)
匹配外部方法执行navigation(ModelMap model)
b)因为你显然是在试图向控制器提出建议,所以有一些注意事项:
proxy-target-class=true
,一切都应该按原样运作,只要确保你没有任何最终方法@RequestMapping
等注释必须在接口上,而不是this section of the Spring MVC reference docs