本文介绍了从SDN 4.0迁移到SDN 4.1.RC1时出现GraphQueryLookupStrategy.resolveQuery异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在迁移应用程序以使用SDN 4.1.0.RC1,但是在尝试启动应用程序后遇到了一些问题.我已经进行了必要的配置更改,以在远程服务器(localhost:7474)上正确使用HTTPDriver,并且在启动应用程序时,尝试加载spring上下文时,我的存储库之一出现以下错误.

I am in the process of migrating my application to use SDN 4.1.0.RC1 but have encountered a few issues after trying to boot the application. I have made the necessary configuration changes to correctly use the HTTPDriver to my remote server (localhost:7474) and when booting the application I get the following error with one of my repositories while attempting to load the spring context.

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userRepository': Invocation of init method failed; nested exception is java.lang.AbstractMethodError: org.springframework.data.neo4j.repository.query.GraphQueryLookupStrategy.resolveQuery(Ljava/lang/reflect/Method;Lorg/springframework/data/repository/core/RepositoryMetadata;Lorg/springframework/data/repository/core/NamedQueries;)Lorg/springframework/data/repository/query/RepositoryQuery;
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1578)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:545)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:1192)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1116)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1014)
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:545)
    ... 32 common frames omitted
Caused by: java.lang.AbstractMethodError: org.springframework.data.neo4j.repository.query.GraphQueryLookupStrategy.resolveQuery(Ljava/lang/reflect/Method;Lorg/springframework/data/repository/core/RepositoryMetadata;Lorg/springframework/data/repository/core/NamedQueries;)Lorg/springframework/data/repository/query/RepositoryQuery;
    at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.<init>(RepositoryFactorySupport.java:416)
    at org.springframework.data.repository.core.support.RepositoryFactorySupport.getRepository(RepositoryFactorySupport.java:206)
    at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.initAndReturn(RepositoryFactoryBeanSupport.java:251)
    at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.afterPropertiesSet(RepositoryFactoryBeanSupport.java:237)
    at org.springframework.data.neo4j.repository.support.GraphRepositoryFactoryBean.afterPropertiesSet(GraphRepositoryFactoryBean.java:43)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1637)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1574)
    ... 42 common frames omitted

这是似乎在哭泣的香草仓库

This is the vanilia repository that seems to be crying

@Repository
public interface UserRepository extends GraphRepository<User> {

  @Query("MATCH (u:User) where u.authId = {authId} return u limit 1")
  User findOneByAuthId(@Param("authId") Long authId);

}

编辑

似乎可以将spring数据的版本与spring数据neo4j的版本断开.

It looks like it could be a disconnect between the version of spring data and spring data neo4j.

有问题的GraphQueryLookupStrategy ...

The GraphQueryLookupStrategy in question...

/*
 * Copyright (c)  [2011-2016] "Pivotal Software, Inc." / "Neo Technology" / "Graph Aware Ltd."
 *
 * This product is licensed to you under the Apache License, Version 2.0 (the "License").
 * You may not use this product except in compliance with the License.
 *
 * This product may include a number of subcomponents with
 * separate copyright notices and license terms. Your use of the source
 * code for these subcomponents is subject to the terms and
 * conditions of the subcomponent's license, as noted in the LICENSE file.
 *
 */

package org.springframework.data.neo4j.repository.query;

import org.neo4j.ogm.session.Session;
import org.springframework.data.projection.ProjectionFactory;
import org.springframework.data.repository.core.NamedQueries;
import org.springframework.data.repository.core.RepositoryMetadata;
import org.springframework.data.repository.query.QueryLookupStrategy;
import org.springframework.data.repository.query.RepositoryQuery;

import java.lang.reflect.Method;

/**
 * @author Mark Angrish
 * @author Luanne Misquitta
 * @author Oliver Gierke
 */
public class GraphQueryLookupStrategy implements QueryLookupStrategy {

    private final Session session;

    public GraphQueryLookupStrategy(Session session) {
        this.session = session;
    }

    /* 
     * (non-Javadoc)
     * @see org.springframework.data.repository.query.QueryLookupStrategy#resolveQuery(java.lang.reflect.Method, org.springframework.data.repository.core.RepositoryMetadata, org.springframework.data.projection.ProjectionFactory, org.springframework.data.repository.core.NamedQueries)
     */
    @Override
    public RepositoryQuery resolveQuery(Method method, RepositoryMetadata metadata, ProjectionFactory factory,
        NamedQueries namedQueries) {
        return new GraphQueryMethod(method, metadata, factory, session).createQuery();
    }
}

看来我有一个QueryLookupStrategy,我期望方法RepositoryQuery resolveQuery(Method method, RepositoryMetadata metadata, NamedQueries namedQueries);被实现,但显然不是.我认为这现在是一个依赖性问题,将对我需要与SDN兼容的Spring Data版本进行进一步调查

It appears the QueryLookupStrategy I have is expecting a method RepositoryQuery resolveQuery(Method method, RepositoryMetadata metadata, NamedQueries namedQueries); to be implemented which clearly it is not. I assume this is now a dependency issue and will investigate further with the version of Spring Data I need to be compliant with SDN

/*
 * Copyright 2008-2010 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.springframework.data.repository.query;

import java.lang.reflect.Method;
import java.util.Locale;

import org.springframework.data.repository.core.NamedQueries;
import org.springframework.data.repository.core.RepositoryMetadata;
import org.springframework.util.StringUtils;

/**
 * Strategy interface for which way to lookup {@link RepositoryQuery}s.
 * 
 * @author Oliver Gierke
 */
public interface QueryLookupStrategy {

    public static enum Key {

        CREATE, USE_DECLARED_QUERY, CREATE_IF_NOT_FOUND;

        /**
         * Returns a strategy key from the given XML value.
         * 
         * @param xml
         * @return a strategy key from the given XML value
         */
        public static Key create(String xml) {

            if (!StringUtils.hasText(xml)) {
                return null;
            }

            return valueOf(xml.toUpperCase(Locale.US).replace("-", "_"));
        }
    }

    /**
     * Resolves a {@link RepositoryQuery} from the given {@link QueryMethod} that can be executed afterwards.
     * 
     * @param method
     * @param metadata
     * @param namedQueries
     * @return
     */
    RepositoryQuery resolveQuery(Method method, RepositoryMetadata metadata, NamedQueries namedQueries);
}

推荐答案

好的,因此,如果遇到此问题,有一种非常简单的解决方法.请参阅 http://projects.spring.io/spring-data/上的文档.此异常是由与spring数据公共模块的版本冲突引起的. neo4j在4.1.0.RC1版本中实现的接口已更改,因此引发了此异常.

Okay, so if you run into this issue there is a pretty straight forward way to resolve it. Please see the documentation at http://projects.spring.io/spring-data/ . This exception was caused by version conflicts with the spring data commons module. The interface that neo4j implements in version 4.1.0.RC1 has changed and thus this exception is thrown.

要解决此问题,请使用Spring Data发布系列BOM并将其设置为发布Hopper-RC1.由于我使用gradle,所以下面是说明,但您也可以在上面的链接中找到它们.

To Resolve use the Spring Data release train BOM and set it to release Hopper-RC1 . Since I use gradle the instructions are below but you can also find them at the link above.

相关的构建脚本已简化...

Relevant build script simplified...

buildscript {
  dependencies {
    classpath "io.spring.gradle:dependency-management-plugin:0.4.0.RELEASE"
  }
}

apply plugin: "io.spring.dependency-management"

dependencyManagement {
  imports {
    mavenBom 'org.springframework.data:spring-data-releasetrain:Hopper-RC1'
  }
}

dependencies {
    compile 'org.springframework.data:spring-data-neo4j:4.1.0.RC1'
}repositories {
    maven {
        url 'https://repo.spring.io/libs-milestone'
    }
}

干杯

史蒂夫

这篇关于从SDN 4.0迁移到SDN 4.1.RC1时出现GraphQueryLookupStrategy.resolveQuery异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-03 11:38