AspectJ aspect not weaving Spring MVC methods with @RequestMapping annotation

I have a standalone aspectJ library ( not related to spring in any way) that I added to app server classpath to monitor the running applications using Load Time Weaving

The aspect work perfectly with all methods ( domain, service, DAO...) but for some reason it doesn't recognize Spring MVC methods with @RequestMapping annotation even if the pointcut expression is matching the controller class and the method name

Is there a different rule for Spring MVC controllers mapping methods ( or Controllers in general from other frameworks too) that needs to be handled separately.

The aspect weaves into other public and private methods in the @Controller classes but not into the @RequestMapping methods specifically.

Note: im not looking for a spring MVC specific solution ( unless it is the only option), I want to be able to weave into any type of classes and methods regardless of the framework without having to modify the running applications.

Here is my code.

public aspect MethodExecutionTimeAspect {

private CollectedData collectedData;

public MethodExecutionTimeAspect() {
    // some initialiation logic.
}


pointcut publicOperation() : execution(public * com.mycompany.myproject..*());

Object around() : publicOperation() {
    // do something
    Object ret = proceed();
     // do something.
    return ret;
  }

}

package com.mycompany.myproject.webapp.springmvc;


@Controller
public class HomeController {

@Resource(name="productService")
private ProductService productService;

@RequestMapping(value = {"/home.do", "/"})
public String displayHomePage(ModelMap map) {
    List<Product> featuredProducts = productService.getFeaturedProducts();
    map.put("featuredProducts", featuredProducts);
    return "homePage";
}

}


The pointcut only matches methods without any arguments. The displayHomePage method takes a map parameter. Try

pointcut publicOperation() : execution(public * com.mycompany.myproject..*(..));

With the added .. this pointcut will match any public methods within your specified package, regardless of how many arguments there are - if any.

链接地址: http://www.djcxy.com/p/77254.html

上一篇: @AspectJ类级别注释Annotation作为方法参数的建议

下一篇: AspectJ方面不使用@RequestMapping注释编织Spring MVC方法