Attempt to map AspectJ pointpoint signature for any methods containing variable

I want to create a pointcut that matches any method in my web controller that contains ModelMap:

pointcut addMenu(ModelMap modelMap) : execution (public String example.web.MyController.*(..)) && args (modelMap); before(ModelMap modelMap) : addMenu(modelMap) { // Do stuff with modelMap... } 

My problem is that this only matches methods with the ModelMap parameter ONLY , the others are not mapped because they contain too many parameters. For example, this is not intercepted due to the "req" parameter:

 public String request(HttpServletRequest req, ModelMap modelMap) { // Handle request } 

Is there a way to map all methods to a ModelMap parameter without adding a pointcut delegate for every possible combination of parameters?

+4
source share
1 answer

You can use wildcards * or .. to flexibly express arguments.

 pointcut addMenu(ModelMap modelMap) : execution (public String example.web.MyController.*(..)) && args (*, modelMap); 

See AspectJ: parameter in pointcut

+4
source

Source: https://habr.com/ru/post/1300653/


All Articles