title: Why @Autowired(required=false) do not work on @Configuration beans?
body: <p>Let explain with an example:</p>
  
  <p>Having this bean:</p>
  
  <pre><code>public class Foo {
      private String name;
  
      Foo(String name) {
          this.name = name;
      }
  
      public String getName() {
          return this.name;
      }
  }
  </code></pre>
  
  <p>And this service:</p>
  
  <pre><code>public class FooService {
      private Foo foo;
  
      FooService(Foo foo) {
          this.foo = foo;
      }
  
      Foo getFoo() {
          return this.foo;
      }
  }
  </code></pre>
  
  <p>Given the following Spring configuration:</p>
  
  <pre><code>@Configuration
  public class SpringContext {
  //    @Bean
  //    Foo foo() {
  //        return new Foo("foo");
  //    }
  
      @Bean
      @Autowired(required = false)
      FooService fooService(Foo foo) {
          if (foo == null) {
              return new FooService(new Foo("foo"));
          }
          return new FooService(foo);
      }
  }
  </code></pre>
  
  <p>For completeness here is a simple unit test:</p>
  
  <pre><code>@RunWith(SpringJUnit4ClassRunner.class)
  @ContextConfiguration(classes = {SpringContext.class})
  public class SpringAppTests {
      @Autowired
      private FooService fooService;
  
      @Test
      public void testGetName() {
          Assert.assertEquals("foo", fooService.getFoo().getName());
      }
  }
  </code></pre>
  
  <p><strong>Then loading the context will throw a NoSuchBeanDefinitionException (Foo).</strong></p>
  
  <p>Can anyone see anything wrong/missing on this example, or provide me a reason for that?</p>
  
  <p>Thank you! Christian</p>