GraphDatabase API如何处理neo4j日志记录

时间:2013-04-05 18:12:22

标签: api logging neo4j

嗨,我正在尝试使用以下命令运行查询:

final GraphDatabaseService graphDatabaseService = new EmbeddedGraphDatabase("http://localhost:7474/db/data");
ExecutionEngine engine = new ExecutionEngine(graphDatabaseService,StringLogger.DEV_NULL);
ExecutionResult result = engine.execute("START n=node(0) RETURN n");

但是,在执行代码时会触发异常:

  

线程“main”中的异常java.lang.NoClassDefFoundError:   阶/ Function0

你能给我一些关于如何解决这个问题的建议吗,任何人都有同样的问题吗?

感谢。

1 个答案:

答案 0 :(得分:0)

<dependency>
  <groupId>org.neo4j</groupId>
  <artifactId>neo4j-rest-graphdb</artifactId>
  <version>1.9.M04</version>
</dependency>

然后在你的java代码中使用它:

import org.neo4j.rest.graphdb.RestAPI;
import org.neo4j.rest.graphdb.RestAPIFacade;
import org.neo4j.rest.graphdb.query.RestCypherQueryEngine;
import org.neo4j.rest.graphdb.util.QueryResult;

import java.util.Map;

import static org.neo4j.helpers.collection.MapUtil.map;

public class RestApiTest {
    public static void main(String[] args) {
        final RestAPI api = new RestAPIFacade("http://localhost:7474/db/data");
        final RestCypherQueryEngine engine = new RestCypherQueryEngine(api);
        final QueryResult<Map<String,Object>> result = engine.query("start n=node({id}) return n.name, id(n) as id", map("id", 0));
        for (Map<String, Object> row : result) {
            long id=((Number)row.get("id")).longValue();
            String name= (String) row.get("n.name");
        }
    }
}