title: Spring Boot, MockMVC and MessageSource
body: <p>so here's a very basic spring-boot project with just 6 classes. </p>
  
  <p><a href="https://github.com/paranoiabla/spring-boot-mockmvc" rel="nofollow">https://github.com/paranoiabla/spring-boot-mockmvc</a></p>
  
  <p>The setup is pretty basic and there's only one test-case which is failing. The exception I get is </p>
  
  <pre><code>org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.springframework.context.NoSuchMessageException: No message found under code 'custom.link' for locale 'en'.
  at org.springframework.context.support.AbstractMessageSource.getMessage(AbstractMessageSource.java:159)
  at org.test.MyController.home(MyController.java:29)
  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
  at java.lang.reflect.Method.invoke(Method.java:606)
  at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:177)
  at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:446)
  at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:434)
  at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:943)
  at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:877)
  at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:966)
  at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:857)
  at javax.servlet.http.HttpServlet.service(HttpServlet.java:618)
  at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:842)
  at org.springframework.test.web.servlet.TestDispatcherServlet.service(TestDispatcherServlet.java:65)
  at javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
  </code></pre>
  
  <p>And I belive this is because <code>SpringApplicationContextLoader</code> line <code>255</code>, method <code>addMockServletContext</code> creates a <code>MockServletContext</code> by calling the constructor that only accepts path. As a result inside the <code>MockServletContext</code> the <code>ResourceLoader</code> is initialized with <code>DefaultResourceLoader</code>, which will lookup for resources in the classpath. This way if I have a <code>ReloadableResourceMessageResolver</code> and my property files are in <code>/WEB-INF/messages/base.properties</code> it will never find them because <code>/WEB-INF/messages/base.properties</code> gets transformed to <code>src/main/webapp/WEB-INF/messages/base.properties</code> which is not found in the classpath by the <code>ReloadableMessageSourceResolver</code>. I think when creating the <code>MockServletContext</code> should be able to explicitly pass the <code>FileSystemResourceLoader</code>, right?</p>