2012-05-11 2 views
1

私はspring-mvc Webプロジェクトにspringデータjpaを追加しようとしています。しかし、私のリポジトリが自動的に初期化できないことが判明しました。サービスクラスでNullPointerExceptionが発生しました。私の次のサンプルコードを参照してください。Springデータの使用中にリポジトリが自動的に初期化できないJPA

マイリポジトリ:

public interface SubjectRepository extends JpaRepository<PSubject, String>{ 
public Page<PSubject> findByType(String title, Pageable pageable); 
public Page<PSubject> findByType(String title); 
public Page<PSubject> findByMacaddress(String macaddress, Pageable pageable); 
public Page<PSubject> findByMacaddress(String macaddress); 
public Page<PSubject> findByUri(String uri); 

}

マイコントローラ:

@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); 
.... 
} 
} 

マイサービス:

​​

マイ設定:

<?xml version="1.0" encoding="UTF-8"?> 
<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"> 
.... 
<jpa:repositories base-package="com.mypacke.repository" repository-impl-postfix="Impl" entity-manager-factory-ref="entityManagerFactory" transaction-manager-ref="transactionManager"/> 

....

私はこのラインsubjectRepository.findOne(対象)で見つかったが、subjectRepositoryがnullの場合、 私の質問は、このpost

+0

を初期化されることを行う場合は、持続していますsrc/main/resources/META-INFの下にence.xmlドキュメントがありますか?また、jpa:respoitories要素のrepository-impl-postfix属性を削除すると、spring-data管理されたインターフェイスではなく、repoの実装を探す可能性があります。 – dardo

+0

はい、META-INFフォルダにpersistence.xmlファイルがあります。そして、私はすでにリポジトリ - impl - postfix属性を削除しようとしました。 – Tom

答えて

0

@Autowired注釈が声明によって活性化されると似ています。

<context:component-scan base-package="base.package"/> 

uは、それが

関連する問題