繁体   English   中英

使用MockMvc时如何在测试代码中加载messages.properties

[英]how load messages.properties in test code when using MockMvc

我使用MockMvc为spring mvc测试控制器编写测试代码。 很好! 但是我对messages.properties有一些问题。

我已将“ messageResource”注册到applicationContext.xml。 并且我已经用property-placeholder检查了此文件。

但是,它在测试代码中不起作用。 但它正在Web服务器中运行。 如何将messages.properties设置为MockMvc?

这是我的测试代码中的applicationContext.xml。

<bean id="messageSource"
class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
<property name="basename" value="classpath:messages" />
<property name="defaultEncoding" value="UTF-8"/>

这是我的测试代码。 请帮我。;

@Test
public void addUserWithPostToSuccess() throws Exception {
    MvcResult result = mvc.perform(post("/user/add/index").param("loginId", "LOGIN_ID").param("name", "NAME").param("password", "PASSWORD"))
                          .andExpect(status().isOk())
                          .andReturn();
    Map<String, Object> model = result.getModelAndView().getModel();
}

解决了 这是我的错。 messages.properties文件的位置

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM