How to set servlet path for each request through MockMvc

Is it possible to set the servlet path for all requests (get, post, put, delete) that go through MockMvc?

The Spring dispatch servlet is displayed in / rest / * But in my test I need to remove the / rest part in the url, otherwise the Spring test will not recognize the controller.

EDIT

@Sotirios:

Something is possible, for example:

public class MyWebTests {

    private MockMvc mockMvc;

    @Before
    public void setup() {
        mockMvc = standaloneSetup(new AccountController())
            .defaultRequest(get("/")
            .contextPath("/app").servletPath("/main")
            .accept(MediaType.APPLICATION_JSON).build();

}}

But I'm wondering how to set the servlet path for all requests. Above the code is http://docs.spring.io/spring/docs/3.2.x/spring-framework-reference/html/testing.html .

Or can you only define servletPath using standaloneSetup?

+4
source share
1 answer

ServletException ( "Circular view path..." ), , MockMvc.

, @ResponseBody. , , viewName "servletPath/callPath", "callPath", ServletException. , servletPath , , , , .

.defaultRequest(get("/").servletPath("/main")) 

. , .

+3

Source: https://habr.com/ru/post/1527371/


All Articles