【问题标题】:GraphQueryLookupStrategy.resolveQuery exception on migration from SDN 4.0 to SDN 4.1.RC1从 SDN 4.0 迁移到 SDN 4.1.RC1 时出现 GraphQueryLookupStrategy.resolveQuery 异常
【发布时间】:2016-07-24 07:10:03
【问题描述】:

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

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

这是似乎在哭泣的vanilia仓库

@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 data 版本和 spring data neo4j 之间的脱节。

有问题的 GraphQueryLookupStrategy...

/*
 * 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 版本

/*
 * 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);
}

【问题讨论】:

    标签: neo4j spring-boot spring-data-neo4j spring-data-neo4j-4


    【解决方案1】:

    好的,所以如果您遇到这个问题,有一个非常直接的方法可以解决它。请参阅http://projects.spring.io/spring-data/ 的文档。此异常是由于与 spring data commons 模块的版本冲突引起的。 Neo4j 在 4.1.0.RC1 版本中实现的接口发生了变化,因此抛出了这个异常。

    要解决使用 Spring Data release train BOM 并将其设置为 release Hopper-RC1 。由于我使用 gradle,所以说明如下,但您也可以在上面的链接中找到它们。

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

    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'
        }
    }
    

    干杯,

    史蒂夫

    【讨论】:

    • 这行得通。现在你可以使用 Hopper-RELEASE 了,这仍然有效。
    【解决方案2】:

    扩展 @Holycowzer 对 Maven 用户的回答。将以下行添加到您的构建 POM.xml。请注意,这将位于您的主要 &lt;dependencies /&gt; 标记集之外。

    <dependencyManagement>
      <dependencies>
        <dependency>
            <groupId>org.springframework.data</groupId>
            <artifactId>spring-data-releasetrain</artifactId>
            <version>Hopper-SR1</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
      </dependencies>
    </dependencyManagement>
    

    我注意到一些导入在执行此操作时中断,只需将它们显式添加为您的 POM 中的依赖项,一切都会按预期工作。

    【讨论】:

      猜你喜欢
      • 2021-02-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-10-10
      • 1970-01-01
      • 2021-02-02
      相关资源
      最近更新 更多