title: Spring pure annotation with autowired
body: <p>I am trying to do a full annotations (no xml) implementation of Spring. The autowired members are not being populated. From my research, there are 3 things to do:</p>
  
  <ul>
  <li><p>Set up a config file that manages the bean</p></li>
  <li><p>Use <code>@Autowired</code> to get the bean to the file</p></li>
  <li><p>Instantiate an application context to get the ball rolling</p></li>
  </ul>
  
  <p>It is difficult to find a complete example of this which uses annotations only, so I don't have much to reference. Most examples use at least some xml.</p>
  
  <p>There is no error message, so I don't have any idea where the problem is. The value is just null. Here are my files:</p>
  
  <p>Trivial.java</p>
  
  <pre><code>public class Trivial {
  
      public TrivialBean trivialBean;
  
      @Autowired
      public void setTrivialBean(TrivialBean trivialBean) {
          this.trivialBean = trivialBean;
      }
  
      public static void main(String...args) {
  
          ApplicationContext context
                  = new AnnotationConfigApplicationContext(
                  TrivialConfig.class);
  
          new Trivial().go();
      }
  
      private void go() {
  
          System.out.println("trivialBean: " + trivialBean);
      }
  }
  </code></pre>
  
  <p>TrivialBean.java</p>
  
  <pre><code>public class TrivialBean {
  
      public String foo = "TEST TEST TEST";
  
      @Override
      public String toString() {
          return foo;
      }
  }
  </code></pre>
  
  <p>TrivialConfig.java</p>
  
  <pre><code>@Configuration
  public class TrivialConfig {
  
      @Bean
      public TrivialBean trivialBean() {
          return new TrivialBean();
      }
  }
  </code></pre>
  
  <p>I would expect this to output <code>trivialBean: TEST TEST TEST</code>, but is just outputs <code>trivialBean: null</code></p>