我正在使用带有spring3的java,我有以下控制器的服务方法
@Override
public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
}我有以下方法为每个方法执行日志记录,我想为每个服务方法调用此方法
public void performLog(HttpServletRequest request){
//process params and log msg
log.debug()
}请告诉我如何在服务方法之后自动调用performLog(request)方法?
发布于 2012-01-03 15:03:25
为此,您必须使用Spring AOP。使用@Before注释指定必要的切入点。将这个方法放在一个用@Aspect注解的类中。类似于
@Aspect
public class BeforeExample {
@Pointcut("execution(ModelAndView com.xyz.myapp.MyController.handleRequest(..))")
public void performLog() {
// ...
}
@Before("execution(* com.xyz.myapp.MyController.*(..))")
public void performLogAll() {
// ...
}
}切入点样本可以在here中找到
有关更多信息,请查看here
https://stackoverflow.com/questions/8681595
复制相似问题