title: Spring 3.1 Java configuration and inner beans
body: <pre><code>@Bean
  public TimedRepository timedRepository(RealRepository repo) {
      return new TimedRepository(repo, timer); // Adds some metrics
  }
  
  @Bean
  public RealRepository realRepository(DataSource ds) {
      return new RealRepository(ds); // The real jdbc implementation
  }
  </code></pre>
  
  <p>In the old XML days I would configure the real repository as an anonymous inner bean. Is it possible to do something similar with the new Java configuration approach? Instantiating the real repository inside the <code>timedRepository</code> factory method is not an option because I want Spring to pick up on annotations on <code>RealRepository</code>. </p>
  
  <p>The motivation is to avoid any other beans to get hold of the real repository implementation. I should also mention that both beans implement a <code>Repository</code> interface that'll be used by any beans depending on the repository (they should not have to know about <code>TimedRepository</code> or <code>RealRepository</code>. </p>