title: Using Spring's ResourceLoader in tests
body: <p>I'm <code>@Autowire</code>ing a <code>org.springframework.core.io.ResourceLoader</code> into one of my <code>@Service</code> classes.</p>
  
  <p>During the tests, I'd like to get access to an instance of a <code>ResourceLoader</code>, so that it can be injected into the service being tested. What's the best way to get a fully functional instance of <code>ResourceLoader</code> during your tests?</p>
  
  <p>If that's not possible, is there an alternative to <code>ResourceLoader</code>? Essentially, I need to have my service read some static files from the project.</p>
  
  <p><strong>Update</strong>:</p>
  
  <p>Started using <code>@RunWith(SpringJUnit4ClassRunner.class)</code> + <code>@ContextConfiguration</code> on my test; however, the <code>ResourceLoader</code> that is now being injected via <code>@Autowire</code> into my service behaves differently than usual (ie. when it's not in the test context). In the test, <code>ResourceLoader#getResource</code> returns a Resource pointing to bad relative path, rather than the proper absolute path which appears during a regular execution.</p>
  
  <p>Some more information discovered while debugging:</p>
  
  <ul>
  <li>During tests, the @Autowired <code>resourceLoader</code> is an instanceof <code>org.springframework.context.support.GenericApplicationContext</code></li>
  <li>During regular execution, <code>resourceLoader</code> is an instance of <code>org.springframework.web.context.support.XmlWebApplicationContext</code></li>
  </ul>