简体   繁体   English

如何让java和neo4j在eclipse中工作

[英]How can I get java and neo4j to work in eclipse

I am using mint 17.2 and have neo4j 3.06 Comunity Edition it is running fine on localhost:7474. 我使用薄荷17.2和neo4j 3.06社区版它在localhost:7474运行正常。

I wish to program in Java 1.08, using Eclipse Mars 2 but I cannot get it to work. 我希望使用Eclipse Mars 2在Java 1.08中编程,但我无法使其工作。

I am using a maven project and have the following in my pom.xml 我正在使用maven项目,并在我的pom.xml中有以下内容

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>com.geekcap.informit</groupId>
  <artifactId>neo4j-sample-app</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>jar</packaging>

  <name>neo4j-sample-app</name>
  <url>http://maven.apache.org</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>

  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>org.neo4j.driver</groupId>
        <artifactId>neo4j-java-driver</artifactId>
        <version>1.0.3</version>
    </dependency>
  </dependencies>
</project>

I have the following in my app.java file 我的app.java文件中有以下内容

package com.geekcap.informit.neo4j_sample_app;


import org.neo4j.driver.v1.*;

public class App 
{

    public static void main( String[] args )
    {
      Driver driver = GraphDatabase.driver("bolt://localhost:7474", AuthTokens.basic("neo4j", "neo4j"));
      Session session = driver.session();

      session.run("CREATE (a:Person {name:'Arthur', title:'King'})" );

      StatementResult result = 
          session.run("Match (a:Person) WHERE a.name = 'Arthur' RETURN a.name AS name, a.title AS title");
      while (result.hasNext()) {
        Record record = result.next();
        System.out.println(record.get("title").asString() + " " + 
            record.get("name").asString());
      }

      session.close();
      driver.close();
    }

I get the following error when I try to run it as a java application. 当我尝试将其作为Java应用程序运行时,我收到以下错误。

Exception in thread "main" org.neo4j.driver.v1.exceptions.ClientException: Unable to process request: Unrecognized SSL message, plaintext connection?
  at org.neo4j.driver.internal.connector.socket.SocketClient.start(SocketClient.java:87)
  at org.neo4j.driver.internal.connector.socket.SocketConnection.<init>(SocketConnection.java:63)
  at org.neo4j.driver.internal.connector.socket.SocketConnector.connect(SocketConnector.java:52)
  at org.neo4j.driver.internal.pool.InternalConnectionPool$1.allocate(InternalConnectionPool.java:191)
  at org.neo4j.driver.internal.pool.InternalConnectionPool$1.allocate(InternalConnectionPool.java:180)
  at org.neo4j.driver.internal.pool.ThreadCachingPool.allocate(ThreadCachingPool.java:212)
  at org.neo4j.driver.internal.pool.ThreadCachingPool.acquireFromGlobal(ThreadCachingPool.java:164)
  at org.neo4j.driver.internal.pool.ThreadCachingPool.acquire(ThreadCachingPool.java:118)
  at org.neo4j.driver.internal.pool.InternalConnectionPool.acquire(InternalConnectionPool.java:109)
  at org.neo4j.driver.internal.InternalDriver.session(InternalDriver.java:53)
  at com.geekcap.informit.neo4j_sample_app.App.main(App.java:12)
Caused by: javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection?
  at sun.security.ssl.EngineInputRecord.bytesInCompletePacket(EngineInputRecord.java:156)
  at sun.security.ssl.SSLEngineImpl.readNetRecord(SSLEngineImpl.java:868)
  at sun.security.ssl.SSLEngineImpl.unwrap(SSLEngineImpl.java:781)
  at javax.net.ssl.SSLEngine.unwrap(SSLEngine.java:624)
  at org.neo4j.driver.internal.connector.socket.TLSSocketChannel.unwrap(TLSSocketChannel.java:186)
  at org.neo4j.driver.internal.connector.socket.TLSSocketChannel.runHandshake(TLSSocketChannel.java:127)
  at org.neo4j.driver.internal.connector.socket.TLSSocketChannel.<init>(TLSSocketChannel.java:95)
  at org.neo4j.driver.internal.connector.socket.TLSSocketChannel.<init>(TLSSocketChannel.java:77)
  at org.neo4j.driver.internal.connector.socket.TLSSocketChannel.<init>(TLSSocketChannel.java:70)
  at org.neo4j.driver.internal.connector.socket.SocketClient$ChannelFactory.create(SocketClient.java:235)
  at org.neo4j.driver.internal.connector.socket.SocketClient.start(SocketClient.java:74)
  ... 10 more

The 7474 port is the HTTP port. 7474端口是HTTP端口。 Since you're using the bolt:// protocol, you should connect to the 7687 port. 由于您使用的是bolt://协议,因此应连接到7687端口。 Or actually remove the port since it's the default value: 或者实际上删除端口,因为它是默认值:

Driver driver = GraphDatabase.driver("bolt://localhost", AuthTokens.basic("neo4j", "neo4j"));

Also make sure that the Bolt protocol is actually active on the Neo4j instance, by uncommenting in conf/neo4j.conf (remove the preceding # ): 还要确保在Neo4j实例上实际激活Bolt协议,方法是在conf/neo4j.conf取消注释(删除前面的# ):

dbms.connector.bolt.address=0.0.0.0:7687

or at least, to limit to local connections: 或者至少限制本地连接:

dbms.connector.bolt.address=127.0.0.1:7687

SSL Errors suggest that the client is expecting encrypted channel, but the server is not encrypted (hence the plaintext connection message in the exception stack trace). SSL错误表明客户端期望加密通道,但服务器未加密(因此异常堆栈跟踪中的明文连接消息)。

Looking over the Neo4j manual, you might want to look into the following section to see how to configure the client and / or server for either encrypted or 'clear-text': 查看Neo4j手册,您可能需要查看以下部分,了解如何为加密或“明文”配置客户端和/或服务器:

You can disable SSL (obviously not recommended in production, but useful to diagnose if this is your issue) on the bolt channel by setting the following in your neo4j.conf: 您可以通过在neo4j.conf中设置以下内容来禁用螺栓通道上的SSL(显然不建议在生产中使用,但对于诊断这是否是您的问题很有用):

dbms.connector.bolt.tls_level=DISABLED

And then restart your neo4j instance 然后重启你的neo4j实例

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM