Spring MockMvc似乎不支持;生产;使用WebApplicationInitializer时在@RequestMapping中

Spring MockMvc似乎不支持;生产;使用WebApplicationInitializer时在@RequestMapping中,spring,spring-test-mvc,Spring,Spring Test Mvc,我有以下方法: @RequestMapping(value = "/report.txt", produces = "text/plain;charset=UTF-8", method = RequestMethod.GET) @ResponseBody public String showReport( ... ) 我用以下方法进行测试: @Before public void setup() throws Exception { mockMvc = MockMvcBuilder

我有以下方法:

@RequestMapping(value = "/report.txt", produces = "text/plain;charset=UTF-8", method = RequestMethod.GET)
@ResponseBody
public String showReport(
  ...
)
我用以下方法进行测试:

@Before
public void setup() throws Exception {
    mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).build();
}

@Test
public void reportPage() throws Exception {
    mockMvc.perform(get("/report.txt"))
        .andDo(print())
        .andExpect(status().isOk())
        .andExpect(content().contentType("text/plain;charset=UTF-8"))
.andDo(print())
告诉我
内容类型=[text/plain;charset=ISO-8859-1]

MockMvc似乎没有使用“products”属性中的内容类型。当我在jetty中运行应用程序时,此页面的内容类型是正确的

这始于我们开始使用WebApplicationInitializer之后

我是在春季4.2.2发布

这里还有其他人看到过这个问题吗?有什么解决办法吗

谢谢

-卡吉:)

从这个链接


从这个链接。

我检查了我的一个应用程序,SpringMVC测试正常运行。我将
生成的
设置为
文本/纯文本;charset=ISO-8859-2和andDo(print())
显示相同的
contentType
。看起来您的配置中有什么问题
WebApplicationInitializer
与您的问题无关
WebApplicationInitializer
仅由servlet容器获取。SpringMVC测试不依赖于servlet容器,我认为类似于@ksokol。我有类似的测试,一切正常。谢谢你的评论!:)我和你有同样的问题,我发现在我的单元测试类中添加@EnableWebMvc可以解决这个问题。我还不知道为什么。我在我的一个应用程序中做了一个检查,SpringMVC测试正常运行。我将
生成的
设置为
文本/纯文本;charset=ISO-8859-2和andDo(print())
显示相同的
contentType
。看起来您的配置中有什么问题
WebApplicationInitializer
与您的问题无关
WebApplicationInitializer
仅由servlet容器获取。SpringMVC测试不依赖于servlet容器,我认为类似于@ksokol。我有类似的测试,一切正常。谢谢你的评论!:)我和你有同样的问题,我发现在我的单元测试类中添加@EnableWebMvc可以解决这个问题。不过,目前还不确定原因。
        this.mockMvc.perform(get("/handle").accept(MediaType.TEXT_PLAIN))
        .andExpect(content().contentType(MediaType.valueOf("text/plain;charset=ISO-8859-1")))
        .andExpect(content().contentType("text/plain;charset=ISO-8859-1"))
        .andExpect(content().contentTypeCompatibleWith("text/plain"))
        .andExpect(content().contentTypeCompatibleWith(MediaType.TEXT_PLAIN));