Reputation: 58113
I am using java with spring3 i have following controller's service method
@Override
public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
}
I have the following method which performs logging for every method, i want to call this method for every service method
public void performLog(HttpServletRequest request){
//process params and log msg
log.debug()
}
Please tell me how can i call performLog(request) method after service method automatically ?
Upvotes: 0
Views: 166
Reputation: 9707
You would have to use Spring AOP for it . Use an @Before annotation specifying the necessary pointcut . Place this method in a class annotated with @Aspect . Something similar to
@Aspect
public class BeforeExample {
@Pointcut("execution(ModelAndView com.xyz.myapp.MyController.handleRequest(..))")
public void performLog() {
// ...
}
@Before("execution(* com.xyz.myapp.MyController.*(..))")
public void performLogAll() {
// ...
}
}
Pointcut samples can be found here
Check here for more info
Upvotes: 1