title: Spring - inject JpaRepository in xml-config without using autowiring
body: <p>I'm currently getting started on a project that uses spring-data in combination with JPA/Hibernate.
  Right now, I'm injecting JpaRepositories using @Autowired annotations on the properties in question, e.g.:
  </p>
  
  <pre><code>@Component
  public class EmployeeGenerator implements IDataGenerator {
  ...
      @Autowired
      private IEmployeeDao        dao;
  ...
  }
  </code></pre>
  
  <p>.. where IEmployeeDao is an interface extending JpaRepository that is annotated as @Repository:</p>
  
  <pre><code>@Repository
  public interface IEmployeeDao extends JpaRepository&lt;Employee, Integer&gt; {
  
       /**
       * Finds employees by username.
       *
       * @param username the username
       * @return the list of employees
       */
      List&lt;Employee&gt; findByUsername(String username);
  </code></pre>
  
  <p>Everything works fine using this approach - However, I'm rather used to doing most of my spring configuration work in XML because I personally like the idea of all relevant confguration being in the same place and visible at the first glance.</p>
  
  <p>Now, as far as I understand JPA and spring-data, the repository instances are somehow created by the JPA entity manager, so I should be able to specify them as beans in the spring config xml using.. some kind of factory method?
  I guess I'm looking for something along the lines of:
  </p>
  
  <pre><code>&lt;import resource="classpath:spring/db-context.xml"/&gt;
  
  &lt;bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"&gt;
      &lt;property name="persistenceUnitName" value="..."/&gt;
      &lt;property name="dataSource" ref="..."/&gt;
      &lt;property name="jpaVendorAdapter"&gt;
          &lt;bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"/&gt;
      &lt;/property&gt;
      &lt;property name="jpaProperties"&gt;
          &lt;props&gt;
              &lt;prop key="hibernate.dialect"&gt;org.hibernate.dialect.H2Dialect&lt;/prop&gt;
              &lt;prop key="hibernate.hbm2ddl.auto"&gt;create&lt;/prop&gt;
              &lt;prop key="hibernate.connection.charSet"&gt;UTF-8&lt;/prop&gt;
          &lt;/props&gt;
      &lt;/property&gt;
  &lt;/bean&gt;
  ...
  &lt;bean id="employeeDaoImpl" class="IEmployeeDao"&gt;
       &lt;factory-method="?????"&gt; &lt;!-- Is something like this possible??? --&gt;
  &lt;/bean&gt;
  </code></pre>
  
  <p>After some reading I guess that autowiring the repositories is the "recommended" approach, and I do see some benefits doing it like that,
  but still, out of interest, I'd like to get it working with pure-xml configuration (or at least without @Autowired, that is)</p>