Need help creating a specific pointcut that utilizes a value from a method annotation

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"Call AutoHandling"); autoHandlingComponent.processAutoHandling(); } ... return forward(returnView); }

Basically what I want to do, is have 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 { ...

-------------Problems Reply------------

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
Category:java Views:0 Time:2011-01-21

Related post

Copyright (C), All Rights Reserved.

processed in 0.208 (s). 11 q(s)