title: How does the @Autowired annotation work in Spring?
body: <p>The real question is why am I allowed to write this code in the following two ways : </p>
  
  <pre><code>@Controller
  public class PostController {
  @Autowired 
  private PostService postService;
  
  @Autowired 
  private CommentService commentService;
  
  ....
  }
  </code></pre>
  
  <p>and </p>
  
  <pre><code>@Controller
  public class PostController {
  
  private PostService postService;
  private CommentService commentService;
  
  @Autowired 
  public PostController(PostService postService, CommentService commentService){
      this.postService = postService;
      this.commentService = commentService;
  }
  
  ....
  }
  </code></pre>
  
  <p>Are these snippets identical? Which one is recommended?</p>