I have the following method
@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);
}
Basically what I want to do, is ha开发者_运维百科ve a pointcut on processAutoHandling() But in the @After, I need to use the slot() for @AutoHandling
I tried this, but it does not get called
@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 {
...
You can use the wormhole design pattern for this. I am illustrating using AspectJ byte-code based approach and syntax, but you should be able to get the same effect using an explicit ThreadLocal if you are using Spring's proxy-based AOP.
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()
}
a) It can't work, you are trying to match two different things:
@Around("processAutoHandleCall() &&" +
"@annotation(autoHandling) &&" +
"target(bean) "
)
processHandleCall()
matches the inner method execution autoHandlingComponent.processAutoHandling()
while @annotation(autoHandling)
matches the outer method execution navigation(ModelMap model)
b) since you are obviously trying to advise a Controller, there are a few caveats:
- if you use
proxy-target-class=true
everything should work as is, just make sure you don't have any final methods - if you don't, all your controller methods must be backed by an interface and the
@RequestMapping
etc annotations must be on the interface, not the implementing class as described in this section of the Spring MVC reference docs
精彩评论