title: Can't Autowire ServletContext
body: <p>I'm new with Spring, and I'm trying to use the @Autowire annotation for the ServletContext with my class attribute:</p>
  
  <pre><code>@Controller
  public class ServicesImpl implements Services{
  
      @Autowired
      ServletContext context;
  </code></pre>
  
  <p>I defined the bean for this class in my dispatcher-servlet.xml:</p>
  
  <pre><code>&lt;bean id="services" class="com.xxx.yyy.ServicesImpl" /&gt;
  </code></pre>
  
  <p>But when I try to run a JUnit test it gives the following error:</p>
  
  <pre><code>Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [javax.servlet.ServletContext] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
  </code></pre>
  
  <p>I thought that the ServletContext injection was automatic with spring... How can I solve this?</p>
  
  <p>Thanks!</p>
  
  <p>EDIT: I want to use the servletContext to call the getRealPath() method. Is there any alternative?</p>