title: spring @Autowire property vs setter
body: <p>What is the difference between anotate @Autowired to a property or do it in the setter?</p>
  
  <p>As far as I know they both have the same result, but is there any reason to use one over the other?</p>
  
  <p><strong>UPDATE (to be more concise)</strong></p>
  
  <p>Is there a difference between this</p>
  
  <pre><code>package com.tutorialspoint;
  
  import org.springframework.beans.factory.annotation.Autowired;
  
  public class TextEditor {
     private SpellChecker spellChecker;
  
     @Autowired
     public void setSpellChecker( SpellChecker spellChecker ){
        this.spellChecker = spellChecker;
     }
  
     public void spellCheck() {
        spellChecker.checkSpelling();
     }
  }
  </code></pre>
  
  <p>and this </p>
  
  <pre><code>package com.tutorialspoint;
  
  import org.springframework.beans.factory.annotation.Autowired;
  
  public class TextEditor {
     @Autowired
     private SpellChecker spellChecker;
  
     public TextEditor() {
        System.out.println("Inside TextEditor constructor." );
     }
  
     public void spellCheck(){
        spellChecker.checkSpelling();
     }
  }
  </code></pre>