title: How to use @Autowired in spring
body: <p>my spring.xml is as below</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;beans xmlns="http://www.springframework.org/schema/beans"
      xmlns:context="http://www.springframework.org/schema/context"
      xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xmlns:oxm="http://www.springframework.org/schema/oxm" xmlns:p="http://www.springframework.org/schema/p"
      xsi:schemaLocation="
          http://www.springframework.org/schema/beans     
          http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
          http://www.springframework.org/schema/context 
          http://www.springframework.org/schema/context/spring-context-3.2.xsd
  
  "&gt;
      &lt;context:component-scan base-package="com.mkyong.service" /&gt;
      &lt;context:annotation-config /&gt;
  
  &lt;/beans&gt;
  </code></pre>
  
  <p>and I have Test1 class</p>
  
  <pre><code>package com.mkyong.service;
  
  import org.springframework.stereotype.Component;
  @Component("test1")
  public class Test1 {
  public int i=1;
  }
  </code></pre>
  
  <p>I have a App class</p>
  
  <pre><code>package com.mkyong.common;
  
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.context.ApplicationContext;
  import org.springframework.context.support.ClassPathXmlApplicationContext;
  
  import com.mkyong.service.Test1;
  
  public class App 
  {
      @Autowired
      Test1 test1;
  
      public static void main( String[] args )
      {
          ApplicationContext context = new ClassPathXmlApplicationContext(
                  "spring.xml");
          App app=new App();
  
          System.out.println(app.test1);
      }
  
  }
  </code></pre>
  
  <p>But I get the output as null.I can not Autowire it properly.Where I am doing wrong?</p>