Skip to content
Advertisement

How to setServletPath() in Spring Junit WebTestClient?

JavaScript

This creates a MockHttpServletRequest that is send to the @RestContoller servlets.

Problem: my servlets make use of HttpServletRequest.getServletPath(), but which is always empty using the WebTestClient approach above.

Question: how can I explicit set the servletPath in my junit tests?

Advertisement

Answer

I could solve it as follows, but as this is really hacky, I’d still appreciate a proper solution.

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement