求教:web项目连接不到neo4j数据库
崩溃…… 我刚开始接触neo4j数据库,是一个小白,找了一个GitHub上面应该相对成熟的代码程序进行学习。 web项目可以运行,且不报错,在运行出的web页面中有一个查询按钮是通过调用servlet来获取neo4J中的数据,以达到在页面中可视化的结果,然而在我点击查询按钮后没有出现结果,在控制台中报出了servlet调用异常的报错信息,说是没有在neo4j中获取有效的数据。 运行环境:idea2019.3 + tomcat7 + java11 连接neo4j和项目的驱动使用的neo4j.java.driver.1.4.4. 报错信息如下:
严重: 在路径为[/abc]的上下文中,servlet[DisplayController]的Servlet.service()引发异常
org.neo4j.driver.v1.exceptions.ServiceUnavailableException: Failed to receive any data from the connected address localhost:7687. Please ensure a working connection to the database.
at org.neo4j.driver.internal.security.TLSSocketChannel.channelRead(TLSSocketChannel.java:176)
at org.neo4j.driver.internal.security.TLSSocketChannel.unwrap(TLSSocketChannel.java:235)
at org.neo4j.driver.internal.security.TLSSocketChannel.runHandshake(TLSSocketChannel.java:137)
at org.neo4j.driver.internal.security.TLSSocketChannel.create(TLSSocketChannel.java:85)
at org.neo4j.driver.internal.security.TLSSocketChannel.create(TLSSocketChannel.java:75)
at org.neo4j.driver.internal.net.ChannelFactory.create(ChannelFactory.java:49)
at org.neo4j.driver.internal.net.SocketClient.start(SocketClient.java:126)
at org.neo4j.driver.internal.net.SocketConnection.startSocketClient(SocketConnection.java:92)
at org.neo4j.driver.internal.net.SocketConnection.<init>(SocketConnection.java:67)
at org.neo4j.driver.internal.net.SocketConnector.createConnection(SocketConnector.java:77)
at org.neo4j.driver.internal.net.SocketConnector.connect(SocketConnector.java:50)
at org.neo4j.driver.internal.net.pooling.SocketConnectionPool$ConnectionSupplier.get(SocketConnectionPool.java:216)
at org.neo4j.driver.internal.net.pooling.SocketConnectionPool$ConnectionSupplier.get(SocketConnectionPool.java:198)
at org.neo4j.driver.internal.net.pooling.BlockingPooledConnectionQueue.acquire(BlockingPooledConnectionQueue.java:96)
at org.neo4j.driver.internal.net.pooling.SocketConnectionPool.acquireConnection(SocketConnectionPool.java:149)
at org.neo4j.driver.internal.net.pooling.SocketConnectionPool.acquire(SocketConnectionPool.java:76)
at org.neo4j.driver.internal.DirectConnectionProvider.acquireConnection(DirectConnectionProvider.java:47)
at org.neo4j.driver.internal.DirectConnectionProvider.verifyConnectivity(DirectConnectionProvider.java:67)
at org.neo4j.driver.internal.DirectConnectionProvider.<init>(DirectConnectionProvider.java:41)
at org.neo4j.driver.internal.DriverFactory.createDirectDriver(DriverFactory.java:109)
at org.neo4j.driver.internal.DriverFactory.createDriver(DriverFactory.java:93)
at org.neo4j.driver.internal.DriverFactory.newInstance(DriverFactory.java:67)
at org.neo4j.driver.v1.GraphDatabase.driver(GraphDatabase.java:135)
at org.neo4j.driver.v1.GraphDatabase.driver(GraphDatabase.java:117)
at org.neo4j.driver.v1.GraphDatabase.driver(GraphDatabase.java:92)
at com.shuhan.Neo4jRestAPI.getDriver(Neo4jRestAPI.java:19)
at com.shuhan.Neo4jRestAPI.executeFindRelationCypher(Neo4jRestAPI.java:95)
at com.shuhan.model2.RelationshipBeanDBA.lookInto(RelationshipBeanDBA.java:125)
at com.shuhan.controller.DisplayController.doGet(DisplayController.java:53)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:110)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:492)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:165)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:1025)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:452)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1201)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:654)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:317)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.base/java.lang.Thread.run(Thread.java:834) \n```
报错信息中涉及到的Displaycontroler代码段如下:
```js\n import com.shuhan.model2.RelationshipBeanDBA;
import systemInfo.SystemInfo;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
[@WebServlet](/user/WebServlet)(name = "DisplayController")
public class DisplayController extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doGet(request,response);
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//这句话可以解决从jsp页面接受到中文乱码问题
request.setCharacterEncoding("utf-8");
response.setContentType("text/html; charset=utf-8");
PrintWriter out = response.getWriter();
String selectItem1 = request.getParameter("selectItem1");
String selectItem2 = request.getParameter("selectItem2");
String keyword = request.getParameter("keyword");
String times = request.getParameter("times");//判断这次操作是用户点击查询按钮还是双击节点
String isHide = request.getParameter("isHide");
String nodeType = "";
String nodeName = "";
if(selectItem1!=null&&selectItem1!=""){
if(selectItem2!=null&&selectItem2!=""){
nodeType = selectItem2;
}
else nodeType= selectItem1;
}
nodeName = keyword;
String json = "";
RelationshipBeanDBA relationshipBeanDBA = new RelationshipBeanDBA();
//用户点击的是查询按钮!
if(times.equals("first")||isHide.equals("yes")){
json = relationshipBeanDBA.lookInto(nodeType,nodeName);
}
//用户双击了节点!
else{
//执行新的查询方法(允许多条查询语句语句同时进行)
//先将语句加入到SystemInfo中,然后在得到全部的查询语句
String cypher = "";
StringBuffer stringBuffer = new StringBuffer("");
stringBuffer.append("match p=(:");
stringBuffer.append(nodeType);
stringBuffer.append("{");
stringBuffer.append("名称:");
stringBuffer.append("\"");
stringBuffer.append(nodeName);
stringBuffer.append("\"");
stringBuffer.append("}");
stringBuffer.append(")");
stringBuffer.append("-[*..1]-() return p");
cypher = stringBuffer.toString();
SystemInfo.addCypher(cypher);
//得到所有的查询语句
ArrayList<String> cypherArrayList = SystemInfo.getCypherArrayList();
/*for(int i = 0;i<cypherArrayList.size();i++){
System.out.println(cypherArrayList.get(i));
}*/
json = relationshipBeanDBA.lookIntos(cypherArrayList);
}
out.write(json);
}
} \n```