How to find methods matching pointcut at startup
I'm wondering if there is an easy way to find all methods that match a particular pointcut. For example, I'd like something that can return a list of Methods or JoinPoints so I can get the class name and method name. For example:
Code:
List<JoinPoint> jps = AopUtils.findMatchingJoinPoints(MyAspect.class)
The specifics:
I want to make it easy to expose JMX statistics on some of my public controller handler methods. For example:
Code:
@Controller LoginController {
@RequestMapping("/login")
@JmxTracked
public String login(HttpServletRequest pReq) {...}
To do this, I want to create a some simple @Before advice that keeps a counter of each time the login() method is invoked and then expose that counter over JMX.
Code:
@Aspect public class JmxTrackingAspect {
@Before(@annotation(com.mycompany.JmxTracked))
public void incrementCount() {...}
}
Code:
/** This is will be exposed with one instance for each @JmxTracked method */
public class Counter {
public int getInvokationCount();
}
I know how to write the Aspect for this. However, I need help writing my special MBeanExporter that finds every method that matches the pointcut because I want to create one instance of my counter MBean for each method. This way I can eagerly create all of the MBeans at startup so that the advice can always know the MBean is created and available.
Is there a way to find all of the methods that match a particular pointcut? I would like to find them all at startup and create the MBeans.
Thanks for any tips or pointers.