我的spring jpa poc未能注册存储库。抛出异常
java.lang.IllegalArgumentException:接口必须使用@ org.springframework.data.repository.RepositoryDefinition注释!
我正在提供我所有的感知代码,以便能够通过这个
的人识别出来我的app-context 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)
接口定义如下:
public interface PushAppsRepository extends JpaRepository<PushApps, Long> {
List<PushApps> findByAppId(long appId);
}
但是,您实体中的属性是“appid”。我猜测扫描程序将无法解析此查询,然后期望某种实现。
更改应用程序&#39;适用。或者更好的是仍然可以完全删除它。您的接口将从JPARepository继承一个方法findOne()或getOne(),您可以使用该方法通过PK检索实体。
答案 1 :(得分:0)
您确定堆栈跟踪是指您在上面显示的PushAppsRepository
吗?只有当我们找到一个没有通过某种方式扩展Spring Data Repository
的存储库接口(你清楚地显示的那个)时,才会抛出异常。
调试RepositoryFactorySupport.getRepositoryMetadata(…)
可能会有所帮助,看看分配检查失败的原因。