title: Autowiring in servlet
body: <p>i want to use spring autowiring in servlet so here's my code:</p>
  
  
  
  <pre><code>@Configurable
  public class ImageServlet extends HttpServlet {
  
     @Autowired
     private SystemPropertyDao systemPropertyDao;
  
     @Override
     public void init() throws ServletException {
  
  
     String imagePath = systemPropertyDao.findByID(StaticParam.CONTENT_FOLDER);
  
  }
  </code></pre>
  
  <p>while the <code>SystemPropertyDao</code> is annotated with <code>@Repository</code></p>
  
  <p>and my <strong>applicationContext.xml</strong>:</p>
  
  
  
  <pre><code>&lt;context:component-scan base-package="com.basepackage" /&gt;
  &lt;mvc:annotation-driven /&gt;
  &lt;context:annotation-config /&gt;
  &lt;context:spring-configured/&gt;
  </code></pre>
  
  <p><strong>web.xml</strong>:</p>
  
  
  
  <pre><code>  &lt;servlet&gt;
      &lt;servlet-name&gt;imageServlet&lt;/servlet-name&gt;
      &lt;servlet-class&gt;com.xeno.basepackage.ImageServlet&lt;/servlet-class&gt;
    &lt;/servlet&gt;
  
    &lt;servlet-mapping&gt;
      &lt;servlet-name&gt;imageServlet&lt;/servlet-name&gt;
      &lt;url-pattern&gt;/myimages/*&lt;/url-pattern&gt;
    &lt;/servlet-mapping&gt;
  </code></pre>
  
  <p>sometimes the autowiring works and sometimes it doesn't (the reference to the spring bean systemPropertyDao is null), can anyone please tell me if i am missing something?</p>