0

How can I log all requests in Spring MVC, even the resource not founds ones?

I guess interceptors can not log resource not found requests. What do you suggest?

Anurag Sharma
  • 2,409
  • 2
  • 16
  • 34
  • Look at my answer here https://stackoverflow.com/questions/53461617/get-xml-from-httpservletrequest-and-use-into-endpoint/56301828?noredirect=1#comment99290019_56301828 – Perimosh Sep 09 '19 at 12:12

1 Answers1

1

Have you tried using implementation of javax.servlet.Filter?

Filter in contrary to Spring's interceptor is part of a Java's standard and is executed by the servlet container for each incoming HTTP request..

Spring MVC use exactly one servlet and that is DispatcherServlet which, as the name suggest, disptach received request to correct controller which process the request futher.

Spring even provide few concrete implementations of Filter that can log incoming request for you such as: CommonsRequestLoggingFilter or ServletContextRequestLoggingFilter.

You can choose one of the above implementations or implement Filter interface by yourself - whatever you decide, by using Filter you should be able to log every single request received by your servlet container.

Piotr Podraza
  • 1,941
  • 1
  • 15
  • 26