2014-05-02 79 views
0

我的spring jpa poc未能獲取存儲庫注入。拋出異常春天打開jpa db2錯誤

java.lang.IllegalArgumentException:接口必須使用@ org.springframework.data.repository.RepositoryDe​​finition註釋!

我給我所有的soruce代碼,以便它可以用一個誰通過這個

我的應用程序上下文XML

<?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:p="http://www.springframework.org/schema/p" 
     xmlns:aop="http://www.springframework.org/schema/aop" 
     xmlns:tx="http://www.springframework.org/schema/tx" 
     xmlns:util="http://www.springframework.org/schema/util" 
     xmlns:jdbc="http://www.springframework.org/schema/jdbc" 
     xmlns:context="http://www.springframework.org/schema/context" 
     xmlns:jpa="http://www.springframework.org/schema/data/jpa" 
     xmlns:jee="http://www.springframework.org/schema/jee" 
     xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd 
     http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd 
     http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd 
     http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd 
     http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd 
     http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd 
     http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa.xsd 
     http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-4.0.xsd"> 


<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean" 
      p:persistenceUnitName="POC" 
      p:packagesToScan="com.poc.accountant.orm" 
      p:dataSource-ref="dataSource" 
      p:jpaVendorAdapter-ref="openJpaVendor" /> 


<!--  p:persistenceXmlLocation="classpath*:persistence.xml" --> 

<bean id="openJpaVendor" class="org.springframework.orm.jpa.vendor.OpenJpaVendorAdapter"> 
    <property name="showSql" value="true"/> 
    <property name="databasePlatform" value="org.apache.openjpa.jdbc.sql.DB2Dictionary" /> 
    </bean> 
<bean id="jpaDataSource" class="org.springframework.jndi.JndiObjectFactoryBean"> 
    <property name="jndiName" value="jdbc/tepds"/> 
</bean> 

<jee:jndi-lookup id="dataSource" jndi-name="jdbc/tepds" 
    resource-ref="true" cache="true" /> 
<!-- <context:component-scan base-package="com.poc.accountant.orm"/> --> 
<!-- <context:component-scan base-package="com.poc.accountant.reposotories" /> --> 

<jpa:repositories base-package="com.poc.accountant.reposotories"/> 
</beans> 

我的實體類去進行鑑定

package com.poc.accountant.orm; 

import java.io.Serializable; 
import java.util.Date; 
    import javax.persistence.Table; 
import javax.persistence.Column; 
import javax.persistence.Entity; 
import javax.persistence.GeneratedValue; 
import javax.persistence.GenerationType; 
import javax.persistence.Id; 
import javax.persistence.Temporal; 
import javax.persistence.TemporalType; 

/** 
* @author Fryder 
* 
*/ 
@Entity 
    @Table(name = "POC.PUSHAPPS") 
public class PushApps implements Serializable { 

    /** 
    * generated serial version ID 
    */ 
    private static final long serialVersionUID = -6763892550710204820L; 

    @Id 
    @Column(name = "appid") 
    @GeneratedValue(strategy = GenerationType.AUTO) 
    private Long appid; 

    @Column(name = "msgid") 
    private String msgid; 

    @Column(name = "severity") 
    private String severity; 

    @Column(name = "application") 
    private String application; 

    @Column(name = "source") 
    private String source; 

    @Column(name = "component") 
    private String component; 

    @Column(name = "enabled") 
    private Boolean enabled; 

    @Column(name = "appgroup") 
    private Long appgroup; 

    @Column(name = "last_err") 
    @Temporal(TemporalType.TIMESTAMP) 
    private Date lastErr; 

    @Column(name = "last_err_sent") 
    @Temporal(TemporalType.TIMESTAMP) 
    private Date lastErrSent; 

    //getters and setters stripped 

} 

我的存儲庫類別

package com.poc.accountant.reposotories; 
import java.util.List; 

import javax.annotation.Resource; 

import org.springframework.data.jpa.repository.JpaRepository; 

import com.poc.accountant.orm.PushApps; 

/** 
* @author Fryder 
* 
*/ 
public interface PushAppsRepository extends JpaRepository<PushApps, Long> { 

    List<PushApps> findByAppId(long appId); 

} 

我的錯誤日誌

7 poc WARN [[ACTIVE] ExecuteThread: '8' for queue: 'weblogic.kernel.Default (self-tuning)'] openjpa.Runtime - An error occurred while registering a ClassTransformer with PersistenceUnitInfo: name 'poc', root URL [file:/C:/Development/Src code and Artifacts/accountant-parent/accountant-web/target/classes/]. The error has been consumed. To see it, set your openjpa.Runtime log level to TRACE. Load-time class transformation will not be available. 
10 poc INFO [[ACTIVE] ExecuteThread: '8' for queue: 'weblogic.kernel.Default (self-tuning)'] openjpa.Runtime - OpenJPA dynamically loaded a validation provider. 
167 poc INFO [[ACTIVE] ExecuteThread: '8' for queue: 'weblogic.kernel.Default (self-tuning)'] openjpa.Runtime - Starting OpenJPA 2.0.1 
641 poc TRACE [[ACTIVE] ExecuteThread: '8' for queue: 'weblogic.kernel.Default (self-tuning)'] openjpa.jdbc.SQL - <t 8564204, conn 499> executing stmnt 502 SELECT CURRENT SCHEMA FROM SYSIBM.SYSDUMMY1 
651 poc TRACE [[ACTIVE] ExecuteThread: '8' for queue: 'weblogic.kernel.Default (self-tuning)'] openjpa.jdbc.SQL - <t 8564204, conn 499> [10 ms] spent 
<May 2, 2014 10:12:41 AM EDT> <Warning> <HTTP> <BEA-101162> <User defined listener org.springframework.web.context.ContextLoaderListener failed: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'pushAppsRepository': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Interface must be annotated with @org.springframework.data.repository.RepositoryDefinition!. 
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'pushAppsRepository': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Interface must be annotated with @org.springframework.data.repository.RepositoryDefinition! 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1553) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475) 
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:304) 
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228) 
    Truncated. see log file for complete stacktrace 
Caused By: java.lang.IllegalArgumentException: Interface must be annotated with @org.springframework.data.repository.RepositoryDefinition! 
    at org.springframework.util.Assert.isTrue(Assert.java:65) 
    at org.springframework.data.repository.core.support.AnnotationRepositoryMetadata.<init>(AnnotationRepositoryMetadata.java:48) 
    at org.springframework.data.repository.core.support.RepositoryFactorySupport.getRepositoryMetadata(RepositoryFactorySupport.java:173) 
    at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.afterPropertiesSet(RepositoryFactoryBeanSupport.java:207) 
    at org.springframework.data.jpa.repository.support.JpaRepositoryFactoryBean.afterPropertiesSet(JpaRepositoryFactoryBean.java:84) 
    Truncated. see log file for complete stacktrace 
+0

如果您可以歸檔您的項目並提供一個鏈接,我們可以下載它,那麼重新生成和搜索修補程序會更容易。 –

+0

對不起,我不能上傳或下載從我的網絡文件,但除了只有我有一個Web項目獲取此上下文xml和實例化在weblogic啓動期間,我有彈簧4.0.3罐子在我的庫 – Fryder

回答

0

接口定義如下:

public interface PushAppsRepository extends JpaRepository<PushApps, Long> { 

    List<PushApps> findByAppId(long appId); 

} 

但是在實體的屬性是 'APPID'。我猜測掃描儀將無法解決此查詢,然後將期待某種實施。

將'appid'更改爲appId。或者更好的是仍然去除它競爭。您的接口將繼承JPARepository中的方法findOne()或getOne(),您可以使用該方法通過PK檢索實體。

+0

使用存儲庫沒有工作,我試過了。我也試過庫定義也沒有工作 – Fryder

+0

看到我修改後的答案。 –

+0

謝謝艾倫,我嘗試了2個建議,但仍然是我的相同錯誤。我有彈簧4.03和打開jpa 2.0.1彈簧數據1.5.2發佈在我的maven conf – Fryder

0

您確定堆棧跟蹤是指您上面顯示的PushAppsRepository?只有當我們發現一個存儲庫接口不是以某種方式擴展Spring Data的Repository(您明確表達的那個)時,纔會拋出異常。

它可能有助於調試RepositoryFactorySupport.getRepositoryMetadata(…)並看看爲什麼分配檢查在那裏失敗。