我试图在扩展CrudRepository接口的接口中创建自定义查询。不幸的是,每次我收到java.lang.AbstractMethodError时出于某种原因。请参阅下面的完整堆栈跟踪 据我所知,问题是Spring框架应该神奇地"为我的方法声明创建一个实现,但由于某种原因它没有实现它。
存储库界面:
public interface PresentationRepository extends CrudRepository<Presentation, Integer> {
Iterable<Presentation> findAll(Sort sort);
Page<Presentation> findAll(Pageable pageable);
List<Presentation> findByTitle(String title); // the problematic line
}
演示文稿:
@Entity
@Table(name = "presentation")
public class Presentation {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "presentation_id")
Integer id;
String title;
String logo;
@Column(name = "length")
Integer interval;
@Column(name = "pages")
Integer pageCount;
Date created;
Date modified;
Date approved;
Date published;
Date deleted;
@ManyToMany(fetch = FetchType.EAGER)
@JoinTable(
name = "presentation_filters",
joinColumns = @JoinColumn(name = "presentation_id"),
inverseJoinColumns = @JoinColumn(name = "filter_id")
)
List<Filter> filters;
public Presentation() {
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
// OTHER GETTERS AND SETTERS FOR EVERY ATTRIBUTE
public Map<FilterGroup, List<Filter>> getGroupedFilters() {
Map<FilterGroup, List<Filter>> grouppedFilters = new HashMap<>();
for (Filter filter : filters ) {
if(!grouppedFilters.containsKey(filter.getGroup())) {
grouppedFilters.put(filter.getGroup(), new ArrayList<>());
}
grouppedFilters.get(filter.getGroup()).add(filter);
}
return grouppedFilters;
}
}
堆栈追踪:
2016-05-15 15:33:51.452 INFO 16939 --- [ restartedMain] org.hibernate.Version : HHH000412: Hibernate Core {4.3.11.Final}
2016-05-15 15:33:51.455 INFO 16939 --- [ restartedMain] org.hibernate.cfg.Environment : HHH000206: hibernate.properties not found
2016-05-15 15:33:51.458 INFO 16939 --- [ restartedMain] org.hibernate.cfg.Environment : HHH000021: Bytecode provider name : javassist
2016-05-15 15:33:51.924 INFO 16939 --- [ restartedMain] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {4.0.5.Final}
2016-05-15 15:33:52.326 INFO 16939 --- [ restartedMain] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.MySQL5Dialect
2016-05-15 15:33:52.580 INFO 16939 --- [ restartedMain] o.h.h.i.ast.ASTQueryTranslatorFactory : HHH000397: Using ASTQueryTranslatorFactory
2016-05-15 15:33:53.038 INFO 16939 --- [ restartedMain] org.hibernate.tool.hbm2ddl.SchemaUpdate : HHH000228: Running hbm2ddl schema update
2016-05-15 15:33:53.038 INFO 16939 --- [ restartedMain] org.hibernate.tool.hbm2ddl.SchemaUpdate : HHH000102: Fetching database metadata
2016-05-15 15:33:53.040 INFO 16939 --- [ restartedMain] org.hibernate.tool.hbm2ddl.SchemaUpdate : HHH000396: Updating schema
2016-05-15 15:33:53.069 INFO 16939 --- [ restartedMain] o.hibernate.tool.hbm2ddl.TableMetadata : HHH000261: Table found: SuperCLM.filter
2016-05-15 15:33:53.069 INFO 16939 --- [ restartedMain] o.hibernate.tool.hbm2ddl.TableMetadata : HHH000037: Columns: [filter_id, name, filter_group_id]
2016-05-15 15:33:53.069 INFO 16939 --- [ restartedMain] o.hibernate.tool.hbm2ddl.TableMetadata : HHH000108: Foreign keys: [fk_alrwu05pj4i5155391v1uq1m9]
2016-05-15 15:33:53.070 INFO 16939 --- [ restartedMain] o.hibernate.tool.hbm2ddl.TableMetadata : HHH000126: Indexes: [filter_group_id, primary]
2016-05-15 15:33:53.089 INFO 16939 --- [ restartedMain] o.hibernate.tool.hbm2ddl.TableMetadata : HHH000261: Table found: SuperCLM.filter_group
2016-05-15 15:33:53.093 INFO 16939 --- [ restartedMain] o.hibernate.tool.hbm2ddl.TableMetadata : HHH000037: Columns: [name, filter_group_id, order]
2016-05-15 15:33:53.093 INFO 16939 --- [ restartedMain] o.hibernate.tool.hbm2ddl.TableMetadata : HHH000108: Foreign keys: []
2016-05-15 15:33:53.093 INFO 16939 --- [ restartedMain] o.hibernate.tool.hbm2ddl.TableMetadata : HHH000126: Indexes: [primary]
2016-05-15 15:33:53.109 INFO 16939 --- [ restartedMain] o.hibernate.tool.hbm2ddl.TableMetadata : HHH000261: Table found: SuperCLM.presentation
2016-05-15 15:33:53.109 INFO 16939 --- [ restartedMain] o.hibernate.tool.hbm2ddl.TableMetadata : HHH000037: Columns: [approved, pages, deleted, created, length, logo, modified, published, title, presentation_id]
2016-05-15 15:33:53.109 INFO 16939 --- [ restartedMain] o.hibernate.tool.hbm2ddl.TableMetadata : HHH000108: Foreign keys: []
2016-05-15 15:33:53.110 INFO 16939 --- [ restartedMain] o.hibernate.tool.hbm2ddl.TableMetadata : HHH000126: Indexes: [primary]
2016-05-15 15:33:53.121 INFO 16939 --- [ restartedMain] o.hibernate.tool.hbm2ddl.TableMetadata : HHH000261: Table found: SuperCLM.presentation_filters
2016-05-15 15:33:53.122 INFO 16939 --- [ restartedMain] o.hibernate.tool.hbm2ddl.TableMetadata : HHH000037: Columns: [filter_id, presentation_filter_id, presentation_id]
2016-05-15 15:33:53.122 INFO 16939 --- [ restartedMain] o.hibernate.tool.hbm2ddl.TableMetadata : HHH000108: Foreign keys: [presentation_filters_ibfk_2, presentation_filters_ibfk_1]
2016-05-15 15:33:53.122 INFO 16939 --- [ restartedMain] o.hibernate.tool.hbm2ddl.TableMetadata : HHH000126: Indexes: [filter_id, presentation_id, primary]
2016-05-15 15:33:53.125 INFO 16939 --- [ restartedMain] org.hibernate.tool.hbm2ddl.SchemaUpdate : HHH000232: Schema update complete
2016-05-15 15:33:53.750 WARN 16939 --- [ restartedMain] ationConfigEmbeddedWebApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'presentationController': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: hu.bme.aut.lovasgergely.superclm.server.dao.PresentationRepository hu.bme.aut.lovasgergely.superclm.server.controller.PresentationController.presentationRepository; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'presentationRepository': Invocation of init method failed; nested exception is java.lang.AbstractMethodError: org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$CreateIfNotFoundQueryLookupStrategy.resolveQuery(Ljava/lang/reflect/Method;Lorg/springframework/data/repository/core/RepositoryMetadata;Lorg/springframework/data/projection/ProjectionFactory;Lorg/springframework/data/repository/core/NamedQueries;)Lorg/springframework/data/repository/query/RepositoryQuery;
2016-05-15 15:33:53.752 INFO 16939 --- [ restartedMain] j.LocalContainerEntityManagerFactoryBean : Closing JPA EntityManagerFactory for persistence unit 'default'
2016-05-15 15:33:53.781 INFO 16939 --- [ restartedMain] o.apache.catalina.core.StandardService : Stopping service Tomcat
2016-05-15 15:33:53.810 ERROR 16939 --- [ restartedMain] o.s.boot.SpringApplication : Application startup failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'presentationController': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: hu.bme.aut.lovasgergely.superclm.server.dao.PresentationRepository hu.bme.aut.lovasgergely.superclm.server.controller.PresentationController.presentationRepository; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'presentationRepository': Invocation of init method failed; nested exception is java.lang.AbstractMethodError: org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$CreateIfNotFoundQueryLookupStrategy.resolveQuery(Ljava/lang/reflect/Method;Lorg/springframework/data/repository/core/RepositoryMetadata;Lorg/springframework/data/projection/ProjectionFactory;Lorg/springframework/data/repository/core/NamedQueries;)Lorg/springframework/data/repository/query/RepositoryQuery;
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:334) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1214) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:543) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:772) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:839) ~[spring-context-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:538) ~[spring-context-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:118) ~[spring-boot-1.3.3.RELEASE.jar:1.3.3.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:766) [spring-boot-1.3.3.RELEASE.jar:1.3.3.RELEASE]
at org.springframework.boot.SpringApplication.createAndRefreshContext(SpringApplication.java:361) [spring-boot-1.3.3.RELEASE.jar:1.3.3.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:307) [spring-boot-1.3.3.RELEASE.jar:1.3.3.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1191) [spring-boot-1.3.3.RELEASE.jar:1.3.3.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1180) [spring-boot-1.3.3.RELEASE.jar:1.3.3.RELEASE]
at hu.bme.aut.lovasgergely.superclm.server.ServerApplication.main(ServerApplication.java:10) [classes/:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_65]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_65]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_65]
at java.lang.reflect.Method.invoke(Method.java:497) ~[na:1.8.0_65]
at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49) [spring-boot-devtools-1.3.3.RELEASE.jar:1.3.3.RELEASE]
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: hu.bme.aut.lovasgergely.superclm.server.dao.PresentationRepository hu.bme.aut.lovasgergely.superclm.server.controller.PresentationController.presentationRepository; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'presentationRepository': Invocation of init method failed; nested exception is java.lang.AbstractMethodError: org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$CreateIfNotFoundQueryLookupStrategy.resolveQuery(Ljava/lang/reflect/Method;Lorg/springframework/data/repository/core/RepositoryMetadata;Lorg/springframework/data/projection/ProjectionFactory;Lorg/springframework/data/repository/core/NamedQueries;)Lorg/springframework/data/repository/query/RepositoryQuery;
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:573) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:331) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
... 22 common frames omitted
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'presentationRepository': Invocation of init method failed; nested exception is java.lang.AbstractMethodError: org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$CreateIfNotFoundQueryLookupStrategy.resolveQuery(Ljava/lang/reflect/Method;Lorg/springframework/data/repository/core/RepositoryMetadata;Lorg/springframework/data/projection/ProjectionFactory;Lorg/springframework/data/repository/core/NamedQueries;)Lorg/springframework/data/repository/query/RepositoryQuery;
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1578) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:545) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:1192) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1116) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1014) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:545) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
... 24 common frames omitted
Caused by: java.lang.AbstractMethodError: org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$CreateIfNotFoundQueryLookupStrategy.resolveQuery(Ljava/lang/reflect/Method;Lorg/springframework/data/repository/core/RepositoryMetadata;Lorg/springframework/data/projection/ProjectionFactory;Lorg/springframework/data/repository/core/NamedQueries;)Lorg/springframework/data/repository/query/RepositoryQuery;
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.<init>(RepositoryFactorySupport.java:435) ~[spring-data-commons-1.12.1.RELEASE.jar:na]
at org.springframework.data.repository.core.support.RepositoryFactorySupport.getRepository(RepositoryFactorySupport.java:220) ~[spring-data-commons-1.12.1.RELEASE.jar:na]
at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.initAndReturn(RepositoryFactoryBeanSupport.java:266) ~[spring-data-commons-1.12.1.RELEASE.jar:na]
at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.afterPropertiesSet(RepositoryFactoryBeanSupport.java:252) ~[spring-data-commons-1.12.1.RELEASE.jar:na]
at org.springframework.data.jpa.repository.support.JpaRepositoryFactoryBean.afterPropertiesSet(JpaRepositoryFactoryBean.java:92) ~[spring-data-jpa-1.9.4.RELEASE.jar:na]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1637) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1574) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
... 34 common frames omitted
2016-05-15 15:33:53.815 INFO 16939 --- [ restartedMain] .b.l.ClasspathLoggingApplicationListener : Application failed to start with classpath: [file:/Users/lovas/Projects/SuperCLM/Program/server/target/classes/]
答案 0 :(得分:8)
由于Spring Data Commons jar和Spring Data JPA jar不兼容,可能会出现此问题。请使用mvn dependency:tree
命令进行检查。
答案 1 :(得分:1)
让您的界面扩展JpaRepository
而不是CrudRepository
。
顺便说一句:JpaRepository
延伸CrudRepository