복붙노트

[SPRING] Spring CrudRepository는 사용자 정의 쿼리 메서드 정의에 AbstractMethodError를 발생시킵니다.

SPRING

Spring CrudRepository는 사용자 정의 쿼리 메서드 정의에 AbstractMethodError를 발생시킵니다.

CrudRepository 인터페이스를 확장하는 인터페이스에서 사용자 지정 쿼리를 만들려고합니다. 불행히도 java.lang.AbstractMethodError를받을 때마다 어떤 이유로 든 불행히도. 아래의 전체 스택 추적을 참조하십시오. 이해할 수있는 한, 문제는 스프링 프레임 워크가 메소드 선언에 대한 구현을 "마술처럼"만들어야한다는 것입니다.하지만 어떤 이유로 그것을 만들지는 못합니다.

저장소 인터페이스 :

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/]

해결법

  1. ==============================

    1.이 문제는 Spring Data Commons jar와 Spring Data JPA jar의 비 호환성으로 인해 발생할 수 있습니다. mvn dependency : tree 명령을 사용하여 이것을 확인하십시오.

    이 문제는 Spring Data Commons jar와 Spring Data JPA jar의 비 호환성으로 인해 발생할 수 있습니다. mvn dependency : tree 명령을 사용하여 이것을 확인하십시오.

  2. ==============================

    2.인터페이스가 CrudRepository 대신 JpaRepository를 확장하도록하십시오.

    인터페이스가 CrudRepository 대신 JpaRepository를 확장하도록하십시오.

    Btw : JpaRepository는 CrudRepository를 확장합니다.

  3. from https://stackoverflow.com/questions/37238982/spring-crudrepository-throws-abstractmethoderror-on-custom-query-method-definiti by cc-by-sa and MIT license