title: Autowired JpaRepository is always null
body: <p>I am configuring my JPA2 + Spring project and trying to use JPARepositories but I seem to be getting Null Pointer Exception on the autowired repository object. Please look at the code and help me identify what I am missing.</p>
  
  <pre><code>Pom.xml
      &lt;dependencies&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;commons-logging&lt;/groupId&gt;
          &lt;artifactId&gt;commons-logging&lt;/artifactId&gt;
          &lt;version&gt;1.1.1&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework.data&lt;/groupId&gt;
          &lt;artifactId&gt;spring-data-commons-core&lt;/artifactId&gt;
          &lt;version&gt;1.4.1.RELEASE&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.hibernate.java-persistence&lt;/groupId&gt;
          &lt;artifactId&gt;jpa-api&lt;/artifactId&gt;
          &lt;version&gt;2.0-cr-1&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.slf4j&lt;/groupId&gt;
          &lt;artifactId&gt;slf4j-api&lt;/artifactId&gt;
          &lt;version&gt;1.7.5&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;log4j&lt;/groupId&gt;
          &lt;artifactId&gt;log4j&lt;/artifactId&gt;
          &lt;version&gt;1.2.14&lt;/version&gt;
          &lt;scope&gt;provided&lt;/scope&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework.data&lt;/groupId&gt;
          &lt;artifactId&gt;spring-data-jpa&lt;/artifactId&gt;
          &lt;version&gt;1.2.0.RELEASE&lt;/version&gt;
          &lt;scope&gt;provided&lt;/scope&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;com.google.guava&lt;/groupId&gt;
          &lt;artifactId&gt;guava&lt;/artifactId&gt;
          &lt;version&gt;r09&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;junit&lt;/groupId&gt;
          &lt;artifactId&gt;junit&lt;/artifactId&gt;
          &lt;version&gt;4.11&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework&lt;/groupId&gt;
          &lt;artifactId&gt;spring-core&lt;/artifactId&gt;
          &lt;version&gt;3.2.4.RELEASE&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework&lt;/groupId&gt;
          &lt;artifactId&gt;spring-context&lt;/artifactId&gt;
          &lt;version&gt;3.2.4.RELEASE&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework&lt;/groupId&gt;
          &lt;artifactId&gt;spring-test&lt;/artifactId&gt;
          &lt;version&gt;3.2.4.RELEASE&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework&lt;/groupId&gt;
          &lt;artifactId&gt;spring-aop&lt;/artifactId&gt;
          &lt;version&gt;3.2.4.RELEASE&lt;/version&gt;
      &lt;/dependency&gt;
  &lt;/dependencies&gt;
  </code></pre>
  
  <hr>
  
  <p>Persistence.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;persistence version="2.1"
  xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence    
      http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd"&gt;
  &lt;persistence-unit name="Testing124"
      transaction-type="RESOURCE_LOCAL"&gt;
      &lt;provider&gt;org.eclipse.persistence.jpa.PersistenceProvider&lt;/provider&gt;
      &lt;class&gt;com.myclassregister.model.base.misc.School&lt;/class&gt;
      &lt;shared-cache-mode&gt;ENABLE_SELECTIVE&lt;/shared-cache-mode&gt;
      &lt;properties&gt;
          &lt;property name="eclipselink.jdbc.batch-writing" value="Buffered" /&gt;
          &lt;property name="eclipselink.target-database" value="MySQL" /&gt;
          &lt;property name="eclipselink.jdbc.native-sql" value="false" /&gt;
          &lt;property name="eclipselink.logging.level" value="fine" /&gt;
          &lt;property name="eclipselink.logging.file"
              value="C:\Users\Vineet\workspace1\MyClassRegister\persistance_logging.txt" /&gt;
          &lt;property name="eclipselink.application-location" value="C:\Users\Vineet\workspace1\MyClassRegister" /&gt;
          &lt;property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/testing124"/&gt;
          &lt;property name="javax.persistence.jdbc.user" value="root"/&gt;
          &lt;property name="javax.persistence.jdbc.password" value="test"/&gt;
          &lt;property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/&gt;
      &lt;/properties&gt;
  &lt;/persistence-unit&gt;
  </code></pre>
  
  <p></p>
  
  <p>applicationContext.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;beans xmlns="http://www.springframework.org/schema/beans"
  xmlns:jpa="http://www.springframework.org/schema/data/jpa" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns:jdbc="http://www.springframework.org/schema/jdbc"
      xmlns:context="http://www.springframework.org/schema/context"
  xmlns:tx="http://www.springframework.org/schema/tx"
      xmlns:repository="http://www.springframework.org/schema/data/repository"
  xsi:schemaLocation="
          http://www.springframework.org/schema/beans
          http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
          http://www.springframework.org/schema/data/jpa
          http://www.springframework.org/schema/data/jpa/spring-jpa-1.3.xsd 
          http://www.springframework.org/schema/jdbc
          http://www.springframework.org/schema/jdbc/spring-jdbc-3.2.xsd
          http://www.springframework.org/schema/context 
          http://www.springframework.org/schema/context/spring-context.xsd
          http://www.springframework.org/schema/tx
          http://www.springframework.org/schema/tx/spring-tx-3.2.xsd
          http://www.springframework.org/schema/data/repository
          http://www.springframework.org/schema/data/repository/spring-repository-1.5.xsd"&gt;
  
  &lt;context:component-scan base-package="com.myclassregister.model" /&gt;
  
  &lt;context:annotation-config/&gt;
  
  &lt;bean id="datasource"
      class="org.springframework.jdbc.datasource.DriverManagerDataSource"&gt;
      &lt;property name="driverClassName" value="com.mysql.jdbc.Driver" /&gt;
      &lt;property name="url" value="jdbc:mysql://localhost:3306/testing124" /&gt;
      &lt;property name="username" value="root" /&gt;
      &lt;property name="password" value="test" /&gt;
  &lt;/bean&gt;
  
  &lt;bean id="jpaDialect"
      class="org.springframework.orm.jpa.vendor.EclipseLinkJpaDialect" /&gt;
  
  &lt;bean id="entityManagerFactory"
      class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"&gt;
      &lt;property name="dataSource" ref="datasource" /&gt;
      &lt;property name="persistenceUnitName" value="MyClassRegister" /&gt;
      &lt;property name="jpaDialect" ref="jpaDialect" /&gt;
      &lt;property name="jpaVendorAdapter"&gt;
          &lt;bean
              class="org.springframework.orm.jpa.vendor.EclipseLinkJpaVendorAdapter" /&gt;
      &lt;/property&gt;
      &lt;property name="loadTimeWeaver"&gt;
          &lt;bean
              class="org.springframework.instrument.classloading.SimpleLoadTimeWeaver" /&gt;
      &lt;/property&gt;
  &lt;/bean&gt;
  
  &lt;bean id="helloWorld"
      class="com.myclassregister.model.test.TestGetSchoolListActivity" /&gt;
  
  &lt;jpa:repositories base-package="com.myclassregister.model.repository"&gt;&lt;/jpa:repositories&gt;
  
  &lt;bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"&gt;
      &lt;property name="entityManagerFactory" ref="entityManagerFactory" /&gt;
  &lt;/bean&gt;
  
  &lt;bean id="loadTimeWeaver" class="com.myclassregister.utils.JpaAwareLoadTimeWeaver" /&gt;
  
  &lt;bean
      class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" /&gt;
  
  &lt;/beans&gt;
  </code></pre>
  
  <p>SchoolRepository.java</p>
  
  <pre><code>@Repository
  public interface SchoolRepository 
  extends JpaRepository &lt;School,Long&gt; {
  
  public School findById(Long Id);
  
  public Collection&lt;School&gt; findAllSchools();
  
  }
  </code></pre>
  
  <p>GetSchoolListActivity.java    </p>
  
  <pre><code> @Service
   public final class GetSchoolListActivity {
  
  private static final String PERSISTENCE_UNIT_NAME = "MyClassRegister";
  private static EntityManagerFactory factory;
  
  @Autowired  
  SchoolRepository schoolRepository;
  
  @Transactional(readOnly=true)
  public Collection&lt;School&gt; GetSchools () {
  
      factory = Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_NAME);
      EntityManager em = factory.createEntityManager();
  
      JpaRepositoryFactory jpaRepositoryFactory = new JpaRepositoryFactory(em);
  
          schoolRepository = jpaRepositoryFactory.getRepository(SchoolRepository.class);
  
      Collection&lt;School&gt; schools = new ArrayList &lt;School&gt; ();
      try{
          schools = schoolRepository.findAllSchools();
      }
      catch(Exception e){
      }
      return schools;
  }   
  }
  </code></pre>
  
  <p>Stack Trace</p>
  
  <pre><code>Exception in thread "main" org.springframework.data.mapping.PropertyReferenceException: No property find found for type com.myclassregister.model.base.misc.School
  at org.springframework.data.mapping.PropertyPath.&lt;init&gt;(PropertyPath.java:75)
  at org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:327)
  at org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:353)
  at org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:353)
  at org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:307)
  at org.springframework.data.mapping.PropertyPath.from(PropertyPath.java:271)
  at org.springframework.data.mapping.PropertyPath.from(PropertyPath.java:245)
  at org.springframework.data.repository.query.parser.Part.&lt;init&gt;(Part.java:73)
  at org.springframework.data.repository.query.parser.PartTree$OrPart.&lt;init&gt;(PartTree.java:180)
  at org.springframework.data.repository.query.parser.PartTree$Predicate.buildTree(PartTree.java:260)
  at org.springframework.data.repository.query.parser.PartTree$Predicate.&lt;init&gt;(PartTree.java:240)
  at org.springframework.data.repository.query.parser.PartTree.&lt;init&gt;(PartTree.java:68)
  at org.springframework.data.jpa.repository.query.PartTreeJpaQuery.&lt;init&gt;(PartTreeJpaQuery.java:57)
  at org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$CreateQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:90)
  at org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$CreateIfNotFoundQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:162)
  at org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$AbstractQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:68)
  at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.&lt;init&gt;(RepositoryFactorySupport.java:280)
  at org.springframework.data.repository.core.support.RepositoryFactorySupport.getRepository(RepositoryFactorySupport.java:148)
  at org.springframework.data.repository.core.support.RepositoryFactorySupport.getRepository(RepositoryFactorySupport.java:116)
  at com.myclassregister.api.login.GetSchoolListActivity.GetSchools(GetSchoolListActivity.java:35)
  at com.myclassregister.model.test.TestGetSchoolListActivity.main(TestGetSchoolListActivity.java:12)
  </code></pre>