简体   繁体   中英

how load messages.properties in test code when using MockMvc

I make test codes for spring mvc test controllers with MockMvc. It's good! and but I have some problems for messages.properties.

I have registred "messageResource" to the applicationContext.xml. and I've checked this file with property-placeholder.

but, It's not working in the test code. but It's working in the web server. How do set the messages.properties to the MockMvc?

Here is my applicationContext.xml in my test codes.

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

and here is my test code. please help me.;

@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();
}

It's solved. It's my mistake.;; The location of messages.properties file

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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