title: How Spring Data JPA picks up / identifies underlying JPA Provider?
body: <p>I am learning Spring Data JPA, and for that I am writing Simple standalone application. Here is the sample code:</p>
  
  <h1>Entity class --> User.java</h1>
  
  <pre><code>@Entity
  @Table(name="USER_DETAILS")
  public class User {
      @Id
      @Column(name="SSNID")
      private int ssnID;
      @Column(name="FULLNAME")
      private String fullName;
      @Column(name="CITY")
      private String city;
      // Getters and Setters omitted
  }
  </code></pre>
  
  <h1>The Repository class --> JPADBAccess.java</h1>
  
  <pre><code>@Repository
      public interface JPADBAccess extends CrudRepository&lt;User, Integer&gt; {
  
      }
  </code></pre>
  
  <h1>A simple service class which uses the repository --> DBServices.java</h1>
  
  <pre><code>@Service
  public class DBServices {
  
      @Autowired(required=true)
      private JPADBAccess jPADBAccess;  // How does this work?? ----&gt;(1)
  
      public void saveUser(User user) {
  
          User queriedUser = null;
          jPADBAccess.save(user);
  
      }
  }
  </code></pre>
  
  <h1>The Spring configuration file looks like:</h1>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;beans ... "&gt;
  
  &lt;context:annotation-config/&gt; &lt;!-- This enables the annotation's actions, else annotations don't do their work. --&gt;
  &lt;context:component-scan base-package="com.example.service"/&gt; &lt;!-- This is for component scan --&gt;
  
  &lt;jpa:repositories base-package="com.example.jpa"/&gt; &lt;!-- This enables support for Spring Data JPA. --&gt;
  
  &lt;bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"&gt;
        &lt;property name="dataSource" ref="dataSource"/&gt;
        &lt;property name="jpaVendorAdapter"&gt;
           &lt;bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"&gt;
               &lt;property name="showSql" value="true"/&gt;
               &lt;property name="generateDdl" value="true"/&gt;
            &lt;/bean&gt;
        &lt;/property&gt;
   &lt;/bean&gt;
  
   &lt;bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"&gt;
        &lt;property name="driverClassName" value="org.h2.Driver"/&gt;
        &lt;property name="url" value="jdbc:h2:tcp://localhost:9092/~/test"/&gt;
        &lt;property name="username" value="sa"/&gt;
        &lt;property name="password" value=""/&gt;
   &lt;/bean&gt;
  
   &lt;bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"&gt;
         &lt;property name="entityManagerFactory" ref="entityManagerFactory"/&gt;
   &lt;/bean&gt;
  </code></pre>
  
  <p></p>
  
  <h1>The persistence.xml looks like this:</h1>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;persistence xmlns="http://java.sun.com/xml/ns/persistence" version="1.0"&gt;
      &lt;persistence-unit name="userPersistenceUnit" transaction-type="RESOURCE_LOCAL" &gt;
      &lt;class&gt;com.example.model.User&lt;/class&gt;
  &lt;/persistence-unit&gt;
  </code></pre>
  
  <p></p>
  
  <p>The standalone classes looks like this:</p>
  
  <pre><code>public class MainApp {
      public static void main(String s[]) {
          DBServices dBServices = null;
          User user = new User();
          user.setSsnID(1);
          user.setCity("Blr");
          user.setFullName("Full name");
          ApplicationContext appContext = new ClassPathXmlApplicationContext("spring-config.xml");
          dBServices = (DBServices) appContext.getBean("DBServices");
          dBServices.saveUser(user);
      }
  }
  </code></pre>
  
  <p>Now it works all fine, I am using Hibernate as the JPA provider <strong>(by simply placing the jar's in the classpath)</strong>.</p>
  
  <p>I have following questions:</p>
  
  <p>1) How does DBService gets the instance of JPADBAccess by @Autowire  when there is no bean defined in the configuration file. </p>
  
  <pre><code>    @Autowired(required=true)
      private JPADBAccess jPADBAccess;  // How does this work?? ----&gt;(1)
  </code></pre>
  
  <p>2) How does Spring Data JPA uses or infers that the underlying JPA provider is Hibernate, when there is no mention of Hibernate in any of the configuration file?</p>