title: autowiring servletContext vs implementing servletContextAware
body: <p>I have seen two ways of getting the <code>servletContext</code> bean in the service/controller.</p>
  
  <p>1) simple way is just autowiring:</p>
  
  <pre><code>@Autowired
  ServletContext servletContext;
  </code></pre>
  
  <p>2) the other way is to implement the <code>servletContextAware</code> interface:</p>
  
  <pre><code>@RestController("/mycontroller")
  public myController implements ServletContextAware {
  
      private ServletContext context;
  
      @Override
      public void setServletContext(ServletContext context) {
          this.context = context;
      }
  
     public String getContextPath(){
     return context.getContextPath();
    }
  
  }
  </code></pre>
  
  <p>What are the pros and cons of these two? Which is the recommended way?</p>