title: Spring Autowiring when using Configuration Class
body: <p>I have a xml bean file</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;beans xmlns="http://www.springframework.org/schema/beans"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xmlns:context="http://www.springframework.org/schema/context"
      xsi:schemaLocation="http://www.springframework.org/schema/beans
      http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
      http://www.springframework.org/schema/context
      http://www.springframework.org/schema/context/spring-context-3.0.xsd"&gt;
     &lt;context:annotation-config/&gt;
     &lt;bean id="helloWorld" class="com.a.b.HelloWorld"&gt; 
           &lt;property name="attr1" value="Attr1 from XML"&gt;&lt;/property&gt;
     &lt;/bean&gt;
      &lt;bean id="helloWorld2" class="com.a.b.HelloWorld2"&gt;
          &lt;property name="attr2" value="Attr2 from XML"&gt;&lt;/property&gt;
      &lt;/bean&gt;
  &lt;/beans&gt;
  </code></pre>
  
  <p>And I have use constructor autowiring like this</p>
  
  <pre><code>public class HelloWorld2{
         private String attr2;
         public void setAttr2(String message){
            this.attr2  = message;
         }
  
         public void getAttr2(){
            System.out.println("getAttr2 == " + attr2);
         }
  
  
      }
  
  public class HelloWorld{
         private String attr1;
         private HelloWorld2 helloWorld2;    
         public HelloWorld(){
  
         }
         @Autowired
         public HelloWorld(HelloWorld2 helloWorld2){
             System.out.println("hhh");
             this.helloWorld2 = helloWorld2;
         }
  
  
      public void setAttr1(String message){
            this.attr1  = message;
         }
  
         public void getAttr1(){
            System.out.println("getAttr1 == " + attr1);
         }
         public void getH(){
             helloWorld2.getAttr2();
         }
      }
  </code></pre>
  
  <p>And autowiring is working fine.</p>
  
  <p>Now I want to move my beans to Configuation class.
  But then how to move the code so as autowiring works?</p>
  
  <p>I have tried like this, but its not working</p>
  
  <pre><code>@Configuration
  public class Config {
      @Bean
      public HelloWorld helloWorld(){
          HelloWorld a = new HelloWorld();
          a.setAttr1("Demo Attr1");
          return a;
  
      }
  
      @Bean
      public HelloWorld2 helloWorld2(){
          HelloWorld2 a = new HelloWorld2();
          a.setAttr2("Demo Attr2");
          return a;               
      }
  }
  </code></pre>