title: Spring messageSource works in JSP and not works in jUnit test
body: <p>I have a spring MVC application with servlet-context.xml:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;beans:beans xmlns="http://www.springframework.org/schema/mvc"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns:beans="http://www.springframework.org/schema/beans"
  xmlns:p="http://www.springframework.org/schema/p"
  xmlns:context="http://www.springframework.org/schema/context"
  xmlns:security="http://www.springframework.org/schema/security"
  xsi:schemaLocation="http://www.springframework.org/schema/mvc 
      http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
      http://www.springframework.org/schema/beans 
      http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
      http://www.springframework.org/schema/context 
      http://www.springframework.org/schema/context/spring-context-3.2.xsd
      http://www.springframework.org/schema/security 
      http://www.springframework.org/schema/security/spring-security-3.1.xsd
      "&gt;
  
  &lt;annotation-driven validator="validator"/&gt;
  
  &lt;resources mapping="/resources/**" location="/resources/" /&gt;
  
  &lt;default-servlet-handler/&gt;  
  
  &lt;!-- Apache Tails configuration --&gt;
  &lt;beans:bean class="org.springframework.web.servlet.view.UrlBasedViewResolver" id="tilesViewResolver"&gt;
      &lt;beans:property name="viewClass" value="org.springframework.web.servlet.view.tiles3.TilesView"/&gt;
  &lt;/beans:bean&gt;
  
  &lt;beans:bean class="org.springframework.web.servlet.view.tiles3.TilesConfigurer" id="tilesConfigurer"&gt;
      &lt;beans:property name="definitions"&gt;
          &lt;beans:list&gt;
              &lt;beans:value&gt;/WEB-INF/layouts/layouts.xml&lt;/beans:value&gt;
              &lt;beans:value&gt;/WEB-INF/views/**/views.xml&lt;/beans:value&gt;
          &lt;/beans:list&gt;
      &lt;/beans:property&gt;
  &lt;/beans:bean&gt;
  
  
  &lt;interceptors&gt;
      &lt;beans:bean class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor" p:paramName="lang"/&gt;
  &lt;/interceptors&gt; 
  
  &lt;beans:bean class="org.springframework.context.support.ReloadableResourceBundleMessageSource"
              id="messageSource"
              p:basenames="WEB-INF/i18n/application, WEB-INF/i18n/validation_messages"
              /&gt;
  &lt;beans:bean class="org.springframework.web.servlet.i18n.CookieLocaleResolver"
              id="localeResolver"
              p:cookieName="locale"/&gt;
  
  &lt;beans:bean id="validator" class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean"&gt;
      &lt;beans:property name="validationMessageSource" ref="messageSource"/&gt;
  &lt;/beans:bean&gt;
  
  &lt;context:component-scan base-package="com.myapp.mvc" /&gt;
  </code></pre>
  
  <p></p>
  
  <p>I have only two .properties files in WEB-INF/i18n/ folder:</p>
  
  <p>WEB-INF/i18n/application.properties</p>
  
  <p>WEB-INF/i18n/validation_messages.properties</p>
  
  <p>messageSource works fine in JSP pages:</p>
  
  <pre><code>&lt;%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %&gt;
  &lt;fmt:message key="validation.User.NULL_FIRST_NAME"/&gt;  
  </code></pre>
  
  <p>and in Hibernate validator:</p>
  
  <pre><code>@Entity
  @Table(name="users")
  public class User {
  
  @Id
  @GeneratedValue(strategy = IDENTITY)
  @Column(name = "id", unique = true, nullable = false)
  private Long id;
  
  @Column(name="first_name")
  @NotNull(message = "{validation.User.NULL_FIRST_NAME}")
  @Size(max = 255, message = "{validation.User.TOO_LONG_FIRST_NAME}")
  private String firstName;
  
  //... getters and setters
  }
  </code></pre>
  
  <p>But it doesn't work in jUnit test-class:</p>
  
  <pre><code>@RunWith(SpringJUnit4ClassRunner.class)
  @ContextConfiguration(classes = {JPATestConfig.class})
  public class AbstractJpaTest {
  
  @Inject
  private MessageSource messageSource;
  
  public void fillValidationMessages() {
  Locale locale = null;
  User_NULL_FIRST_NAME = messageSource.getMessage("validation.User.NULL_FIRST_NAME", null, locale);
  }
  }
  </code></pre>
  
  <p>I've try to use MessageSourceAware and different locales but every time I have the same error:</p>
  
  <pre><code>org.springframework.context.NoSuchMessageException: No message found under code 'validation.User.NULL_FIRST_NAME' for locale 'null'.
  at org.springframework.context.support.DelegatingMessageSource.getMessage(DelegatingMessageSource.java:65)
  at org.springframework.context.support.AbstractApplicationContext.getMessage(AbstractApplicationContext.java:1234)
  at com.dominform.mvc.AbstractJpaTest.fillValidationMessages(AbstractJpaTest.java:198)
  at com.dominform.mvc.jpa_tests.UserUtilTest.init(UserUtilTest.java:21)
  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:601)
  at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
  at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
  at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
  at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:24)
  at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:74)
  at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:83)
  at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:72)
  at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:231)
  at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:88)
  at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
  at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
  at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
  at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
  at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
  at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
  at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:71)
  at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
  at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:174)
  at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
  at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
  at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
  at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
  at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
  at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
  </code></pre>
  
  <p>Any ideas?</p>