A
A
Andrey Shishkin2016-04-04 11:06:49
Spring
Andrey Shishkin, 2016-04-04 11:06:49

Testing the Spring REST controller. How to disable request forwarding?

Greetings. I am writing a test for a rest controller marked with the @RestController annotation.
In the test, I check that JSON is returned

mockMvc.perform(get(URI).accept(MediaType.APPLICATION_JSON))
                    .andExpect(status().isOk())
                    //.andExpect(content().contentType(MediaType.APPLICATION_JSON))
                    .andDo(print());

I load the beans using a java config that extends WebMvcConfigurationSupport, thereby pulling up the beans responsible for json and xml serialization.
As a result, I get an empty response with 200 code, and my url is specified in the Forwarded URL parameter.
I believe the request forward occurs after the controller has completed to find the appropriate view. But is it supposed to work like this in the case of @RestController ? I'm expecting my 200th responce with jason in a bodysuit.
What am I doing wrong ?
I can't post the detailed code, sorry.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrey Shishkin, 2016-04-05
@compiler

Answer found. The old version of spring-webmvc 3.2.4 with the old WebMvcConfigurationSupport arrived transitively, in which the necessary bins are not raised, including the resolver I need.
Removed this lib from dependencies. All OK!

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question