java - 使用 Neo4j 2.0 和 Spring Data 3.0 Rest 启动时出现异常

标签 java spring neo4j spring-data-neo4j

我正在尝试升级到 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

Neo4j 和 spring-data 对 Pom.xml 的依赖

<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;

最佳答案

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

<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.ReferenceNodes产生的在 getReferenceNode (http://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;

并查看错误是否仍然发生。

关于java - 使用 Neo4j 2.0 和 Spring Data 3.0 Rest 启动时出现异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21519177/

相关文章:

java - Wicket:更新 DropDownChoice 项目选择事件的模型

java - NoSuchMethodError : com. google.common.base.Preconditions.checkState(ZLjava/lang/String;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)V

java - 将 abel 包裹在复合 Material 中

spring - 云中的 Neo4j

java - 如何使用ssh以编程方式将远程端口3306转发到android中的本地端口并连接到mysql

java - Spring 安全5 : There is no PasswordEncoder mapped for the id "null"

不带 Spring Boot 的 Spring Boot 2 执行器

javascript - Spring中使用@modelAttribute进行Ajax调用参数

mysql - neo4j cypher - 造成关系麻烦

neo4j - 在neo4j(浏览器)中隐藏中间节点