title: What exactly is Field Injection and how to avoid it?
body: <p>I read in some posts about Spring MVC and Portlets that <em>field injection</em> is not recommended. As I understand it, <em>field injection</em> is when you inject a Bean with <code>@Autowired</code> like this:</p>
  
  <pre><code>@Component
  public class MyComponent {
      @Autowired
      private Cart cart;
  }
  </code></pre>
  
  <p>During my research I also read about <em>constructor injection</em>:</p>
  
  <pre><code>@Component
  public class MyComponent {
      private final Cart cart;
  
      @Autowired
      public MyComponent(Cart cart){
         this.cart = cart;
      }
  }
  </code></pre>
  
  <p>What are the advantages and the disadvantages of both of these types of injections?</p>
  
  <hr>
  
  <p><strong>EDIT 1:</strong> As this question is marked as duplicate of <a href="https://stackoverflow.com/questions/7779509/setter-di-vs-constructor-di-in-spring">this question</a> i checked it. Cause there aren't any code examples neither in the question nor in the answers it's not clear to me if i'm correct with my guess which injection type i'm using. </p>