title: My repository can't initialize automatically while using Spring Data JPA
body: <p>I am trying to add spring data jpa to my spring-mvc web project after exploring a couple of tutorials. But I found my repository can't initialize automatically, I got NullPointerException in my service class. Please see my following sample code:</p>
  
  <p>My repository:</p>
  
  <pre><code>public interface SubjectRepository extends JpaRepository&lt;PSubject, String&gt;{
  public Page&lt;PSubject&gt; findByType(String title, Pageable pageable);
  public Page&lt;PSubject&gt; findByType(String title);
  public Page&lt;PSubject&gt; findByMacaddress(String macaddress, Pageable pageable);
  public Page&lt;PSubject&gt; findByMacaddress(String macaddress);
  public Page&lt;PSubject&gt; findByUri(String uri);
  </code></pre>
  
  <p>}</p>
  
  <p>My controller：
  <code></p>
  
  <pre><code>@Controller
  @RequestMapping("/subject")  
  public class VPSubjectController
  {
  ....
  @RequestMapping("/{id}.htm")
      public ModelAndView detail(@PathVariable String id)
      {
          ModelAndView mav = new ModelAndView("subject/detail");
          PSubject subject = subjectService.get(id);
  ....
  }
  }
  </code></pre>
  
  <p></code></p>
  
  <p>My Service：</p>
  
  <pre><code>@Service("subjectService")
  public class SubjectServiceImpl extends VPService implements SubjectService
  {
  
      @Autowired
      private SubjectRepository subjectRepository;
  ......
  @Override
      @Transactional(propagation=Propagation.REQUIRED, readOnly=true)
      public PSubject get(String subject) {
          PSubject subObj = subjectRepository.findOne(subject);
          return subObj;
      }
  .....
  </code></pre>
  
  <p>My configuration:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;beans xmlns="http://www.springframework.org/schema/beans"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
      xmlns:context="http://www.springframework.org/schema/context"
      xmlns:mvc="http://www.springframework.org/schema/mvc"
      xmlns:util="http://www.springframework.org/schema/util"
      xmlns:jpa="http://www.springframework.org/schema/data/jpa"
      xsi:schemaLocation="    
             http://www.springframework.org/schema/beans 
             http://www.springframework.org/schema/beans/spring-beans.xsd 
             http://www.springframework.org/schema/context 
             http://www.springframework.org/schema/context/spring-context.xsd 
             http://www.springframework.org/schema/mvc 
             http://www.springframework.org/schema/mvc/spring-mvc.xsd
             http://www.springframework.org/schema/util 
             http://www.springframework.org/schema/util/spring-util-3.0.xsd
             http://www.springframework.org/schema/data/jpa
             http://www.springframework.org/schema/data/jpa/spring-jpa.xsd"&gt;
  ....
  &lt;jpa:repositories base-package="com.mypacke.repository"  repository-impl-postfix="Impl" entity-manager-factory-ref="entityManagerFactory" transaction-manager-ref="transactionManager"/&gt;
  </code></pre>
  
  <p>....</p>
  
  <p>I found in this line subjectRepository.findOne(subject) ,subjectRepository is null,
  My question is similar this <a href="https://stackoverflow.com/questions/10539417/spring-data-jpa-injection-fails-beancreationexception-could-not-autowire-fi">post</a></p>