0

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 ?

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.