【问题标题】:Exception on Startup with Neo4j 2.0 with Spring Data 3.0 Rest使用 Spring Data 3.0 Rest 启动 Neo4j 2.0 时出现异常
【发布时间】:2014-02-03 03:17:35
【问题描述】:

我正在尝试升级到 Neo4j 2.0 和 Spring Data 3.0。当应用程序启动时,在我的任何代码执行之前,我得到一个空指针。

Caused by: org.springframework.dao.InvalidDataAccessResourceUsageException: Error executing statement MATCH (ref:ReferenceNode {name:{name}}) RETURN ref; nested exception is org.springframework.dao.InvalidDataAccessResourceUsageException: Error executing statement MATCH (ref:ReferenceNode {name:{name}}) RETURN ref; nested exception is java.lang.NullPointerException
at org.springframework.data.neo4j.support.query.CypherQueryEngine.query(CypherQueryEngine.java:56)
at org.springframework.data.neo4j.support.ReferenceNodes.executeQuery(ReferenceNodes.java:77)
at org.springframework.data.neo4j.support.ReferenceNodes.getReferenceNode(ReferenceNodes.java:81)
at org.springframework.data.neo4j.support.typerepresentation.SubReferenceNodeTypeRepresentationStrategy.isStrategyAlreadyInUse(SubReferenceNodeTypeRepresentationStrategy.java:95)
at org.springframework.data.neo4j.support.typerepresentation.TypeRepresentationStrategyFactory.chooseStrategy(TypeRepresentationStrategyFactory.java:56)
at org.springframework.data.neo4j.support.typerepresentation.TypeRepresentationStrategyFactory.<init>(TypeRepresentationStrategyFactory.java:39)
at org.springframework.data.neo4j.config.Neo4jConfiguration.typeRepresentationStrategyFactory(Neo4jConfiguration.java:146)
at org.springframework.data.neo4j.config.Neo4jConfiguration$$EnhancerByCGLIB$$4b018b97.CGLIB$typeRepresentationStrategyFactory$6(<generated>)
at org.springframework.data.neo4j.config.Neo4jConfiguration$$EnhancerByCGLIB$$4b018b97$$FastClassByCGLIB$$5306fd26.invoke(<generated>)
at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228)
at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:286)
at org.springframework.data.neo4j.config.Neo4jConfiguration$$EnhancerByCGLIB$$4b018b97.typeRepresentationStrategyFactory(<generated>)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:160)
... 112 more
Caused by: org.springframework.dao.InvalidDataAccessResourceUsageException: Error executing statement MATCH (ref:ReferenceNode {name:{name}}) RETURN ref; nested exception is java.lang.NullPointerException
at org.springframework.data.neo4j.support.query.CypherQueryEngine.parseAndExecuteQuery(CypherQueryEngine.java:67)
at org.springframework.data.neo4j.support.query.CypherQueryEngine.query(CypherQueryEngine.java:53)
... 128 more
Caused by: java.lang.NullPointerException
at org.neo4j.cypher.ExecutionEngine.prepare(ExecutionEngine.scala:75)
at org.neo4j.cypher.ExecutionEngine.execute(ExecutionEngine.scala:60)
at org.neo4j.cypher.ExecutionEngine.execute(ExecutionEngine.scala:65)
at org.neo4j.cypher.javacompat.ExecutionEngine.execute(ExecutionEngine.java:78)
at org.springframework.data.neo4j.support.query.CypherQueryEngine.parseAndExecuteQuery(CypherQueryEngine.java:65)
... 129 more

Pom.xml 上的 Neo4j 和 spring-data 依赖项

<properties>
    <spring.version>3.2.6.RELEASE</spring.version>
    <springSecurity.version>3.2.0.RELEASE</springSecurity.version>
    <jackson.version>1.9.13</jackson.version>
    <neo4j.version>2.0.0</neo4j.version>
    <springDataNeo4j.version>3.0.0.RC1</springDataNeo4j.version>
    <neo4j-rest-graphdb.version>2.0.0</neo4j-rest-graphdb.version>
</properties>
<!--Neo4j-->
    <dependency>
        <groupId>org.neo4j</groupId>
        <artifactId>neo4j</artifactId>
        <version>${neo4j.version}</version>
    </dependency>

    <dependency>
        <groupId>org.springframework.data</groupId>
        <artifactId>spring-data-neo4j</artifactId>
        <version>${springDataNeo4j.version}</version>
    </dependency>


    <dependency>
        <groupId>org.neo4j</groupId>
        <artifactId>neo4j-rest-graphdb</artifactId>
        <version>${neo4j-rest-graphdb.version}</version>
    </dependency>

上下文文件

<neo4j:config graphDatabaseService="graphDatabaseService" />

<bean id="graphDatabaseService" class="org.neo4j.rest.graphdb.RestGraphDatabase">
    <constructor-arg value="http://localhost:7474/db/data"/>
</bean>

<context:annotation-config />

Neo4j 已启动并运行。

当通过http://localhost:7474/browser/ 连接时一切正常,包括有问题的查询 MATCH (ref:ReferenceNode {name:{name}}) RETURN ref;

【问题讨论】:

    标签: java spring neo4j spring-data-neo4j


    【解决方案1】:

    我相信您不需要任何 org.neo4j.* 依赖项。也许它只适用于&lt;artifactId&gt;spring-data-neo4j&lt;/artifactId&gt;&lt;artifactId&gt;spring-data-neo4j-rest&lt;/artifactId&gt;。这是您应该尝试的配置:

    <dependency>
        <groupId>org.springframework.data</groupId>
        <artifactId>spring-data-neo4j</artifactId>
        <version>3.0.0.RC1</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.data</groupId>
        <artifactId>spring-data-neo4j-rest</artifactId>
        <version>3.0.0.RC1</version>
    </dependency>
    

    更新

    可以确定的是,错误信息是由org.springframework.data.neo4j.support.ReferenceNodesgetReferenceNodehttp://bit.ly/1eDYlYS)生成的。

    getReferenceNode 方法仅在 SDN 中的一处调用,即 org.springframework.data.neo4j.support.typerepresentation.SubReferenceNodeTypeRepresentationStrategy (http://bit.ly/LW5gly)。

    此调用正在查找标签为 :ReferenceNode 且属性 name 等于 root 的节点。

    所以我建议尝试使用 Cypher 创建这样一个节点:

    CREATE (n:ReferenceNode {name:"root"}) RETURN n;
    

    看看错误是否仍然发生。

    【讨论】:

    • 感谢您的提示。您不需要 org.neo4j.* 依赖项是对的。我排除了它们,它构建得很好。但是,在服务器启动后,我仍然遇到完全相同的异常。
    • 我发现这个讨论可能与您的问题有关:groups.google.com/forum/#!topic/neo4j/XIHxfqJVWgc “参考节点概念已在 Neo4j 版本 M06 和 RC1 之间被删除。SDN 3.0 M1 仍然使用 Neo4j 2.0 M06并且依赖于参考节点。因此,遗憾的是,SDN 还不能与 Neo4j 2.0 RC1 一起使用。” 但是您使用的是 3.0.0.RC1 而不是 3.0.0.M1,因此您应该检查是否这取决于新版本的 Neo4J。
    • 根据这个commit,好像是包含在3.0.0.RC1中的,是依赖于Neo4j 2.0的。
    • 不幸的是,它没有解决。我认为由于传递给查询的参数为空,所以正在抛出空指针。
    • " 传递给查询的参数为空" - 有什么消息吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-03-05
    • 2015-10-31
    • 1970-01-01
    相关资源
    最近更新 更多