title: Inject null to autowired @Resource member in spring unit test
body: <p>I have implemented some unit tests which use the <a href="http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/testing.html" rel="nofollow noreferrer">Spring Test Framework</a>. The tests include members that get autowired by name, e.g.</p>
  
  <pre><code>@Resource
  private FooBar myFooBar;
  </code></pre>
  
  <p>I configured my test to be able to run with different configurations like mentioned <a href="https://stackoverflow.com/questions/4593530/spring-unit-and-integration-tests/4593727#4593727">here</a>.</p>
  
  <p>Some configurations do not allow to run all tests (e.g. no database available). I want to skip the test in this case. My criteria to skip the test is <code>myFooBar == null</code>.</p>
  
  <pre><code>assumeTrue(myFooBar != null)
  </code></pre>
  
  <p>I am facing the problem how to inject <code>null</code> into this member. I tried</p>
  
  <pre><code>&lt;bean id="myFooBar" class="FooBar"&gt;
    &lt;null /&gt;
  &lt;/bean&gt;
  </code></pre>
  
  <p>But this does not work (<em>Invalid content was found starting with element 'null'...</em>)</p>
  
  <p>If I do not configure the bean in my context.xml I get a <code>NoSuchBeanDefinitionException</code>.</p>
  
  <p>Can't be that hard for Spring to just inject <code>null</code> to my member - but it's definitly hard for me :-)</p>
  
  <p>I have to add that my <code>FooBar</code> class has no default constructor.</p>
  
  <p>Do you have any idea of how to inject <code>null</code> or how to ignore missing bean definitions on autowired test class members?</p>
  
  <p>Regards<br/>
  &nbsp;&nbsp;K. Claszen</p>