我有一个servlet,并希望连接到Neo4j数据库。这样我就可以通过互联网从我的应用程序访问数据库了。但是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)发布于 2013-03-25 15:33:12
解决了!我复制了Tomcat7.0\lib中的Neo4j JAR文件,它完全解决了这个问题!
发布于 2013-03-24 15:34:43
您将希望使用Neo4j的REST api。这是使用Neo4j的标准方法,如果您通过internet访问它(而不是嵌入到您的程序中)。
您需要遵循this tutorial,它向您展示了如何将Neo4j设置为具有REST api的服务器。
就我个人而言,我认为把它嵌入到Java中要容易得多。如果要将其创建为嵌入式Java数据库,则应执行以下操作:
GraphDatabaseService dbService = new EmbeddedGraphDatabase(DB_PATH);然而,当你的程序启动时,你应该只做一次。因此,在程序启动时实例化它,并只使用对它静态引用。(或者更好的做法是,使用Spring并在需要的地方自动连接Neo4jOperations。或者最好的是,使用Spring Data Neo4j!)
发布于 2014-11-27 16:51:27
我也遇到了同样的问题,步骤如下:转到buildpath .here配置构建路径,选择部署程序集,确保其中有常春藤( -> )库。如果没有,可以通过add->java build path entries>ivy(或maven)添加它
如果您已经在外部(不是通过ivy/maven)添加了neo4j库,那么可以将该库添加到部署程序集中。它应该能解决这个问题
https://stackoverflow.com/questions/15595548
复制相似问题