title: In Spring, how can I autopopulate a custom argument to a web @Controller method?
body: <p>In Spring, I can use a <code>Principal</code> object as an argument to a web controller method, and it gets populated.  For example:</p>
  
  <pre><code>public String listTransactionsForAccount(Model model, Principal principal) {
      String username = principal.getName();
      // do something with the username
  }
  </code></pre>
  
  <p>My question is this: How can I pass in a custom object (<code>Account</code>) and have it populate, similar to how Spring populates the <code>Principal</code>?</p>
  
  <p>In my application model, I've got a setup where there are 0..n <code>User</code>s per <code>Account</code>.  I can get the User based off of the <code>Principal</code> but what I'm really after is the <code>Account</code>.  I find that I have to do this in a lot of places:</p>
  
  <pre><code>String username = principal.getName();
  User user = userService.findByUsername(username);
  Long accountId = user.getAccount().getId();
  </code></pre>
  
  <p>It would be ideal if I could just do this:</p>
  
  <pre><code>public String listTransactionsForAccount(Model model, Account account) {
      // do stuff directly with the account
  }
  </code></pre>
  
  <p>How would I go about doing this?</p>