2

我有一个 servlet,想连接到 Neo4j 数据库。这样我就可以通过 Internet 从我的应用程序访问数据库。但是 servlet 给出了错误?难道我做错了什么?

这是我的 servlet 代码。

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws     ServletException, IOException {
PrintWriter out = response.getWriter();
out.println("Hello World");

GraphDatabaseService graphDB = new GraphDatabaseFactory().newEmbeddedDatabase("C:\\Users\\Sourav\\Desktop\\db1");
}

这是网页中返回的错误。

HTTP Status 500 - Servlet execution threw an exception

type Exception report

message Servlet execution threw an exception

description The server encountered an internal error that prevented it from fulfilling     this request.

exception

javax.servlet.ServletException: Servlet execution threw an exception
root cause

java.lang.NoClassDefFoundError: org/neo4j/graphdb/factory/GraphDatabaseFactory
hello.hello.doGet(hello.java:45)
javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
4

3 回答 3

4

你会想要使用 Neo4j 的 REST api。如果您通过 Internet 访问 Neo4j(未嵌入到您的程序中),这是使用 Neo4j 的标准方式。

您将需要遵循本教程,该教程向您展示如何将 Neo4j 设置为具有 REST api 的服务器。

就个人而言,我认为将它嵌入到 Java 中要容易得多。如果您将其创建为嵌入式 Java 数据库,您应该执行以下操作:

GraphDatabaseService dbService = new EmbeddedGraphDatabase(DB_PATH);

但是,您应该只在程序启动时执行一次。因此,在程序启动时实例化它并使用对它的静态引用。(或者更好的是,使用 Spring 并在任何需要的地方自动装配 Neo4jOperations。或者最重要的是,使用Spring Data Neo4j!)

于 2013-03-24T07:34:42.800 回答
2

解决了!!!我在 Tomcat 7.0\lib 中复制了 Neo4j JAR 文件,它完全解决了问题!!!

于 2013-03-25T07:33:11.960 回答
0

我遇到了同样的问题。这里是步骤-转到构建路径->配置构建路径选择部署程序集确保那里有 Ivy(maven) 库。如果没有通过 add->java build path entries->ivy(or maven) 添加

如果您在外部添加了 neo4j 库(不是通过 ivy/maven),则将该库添加到部署程序集中。它应该可以解决问题

于 2014-11-27T08:51:26.960 回答