Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring MVC: Log Controller paths without params

I am trying to add some metric gathering to a Spring MVC app. Lets say I have a controller whose mapping is:

 /User/{username}/Foobar

I want to gather metrics on all controller mapping invocations with the path. Right now I can create a handler/interceptor and look at the requests but that will give me:

/User/Charlie/Foobar

Which is not what I want. I want the controller mapping itself to log. and I don't want to have to add something to every controller. I'd also rather not use AOP if I can help it.

like image 900
ryber Avatar asked May 24 '26 07:05

ryber


1 Answers

It turns out that Spring hangs the best matching controller pattern on the request itself. You can get this from within a handlerinterceptor like this:

 (String)request.getAttribute(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE)
like image 76
ryber Avatar answered May 26 '26 22:05

ryber