简体   繁体   中英

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.

I wish to program in Java 1.08, using Eclipse Mars 2 but I cannot get it to work.

I am using a maven project and have the following in my 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

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.

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. Since you're using the bolt:// protocol, you should connect to the 7687 port. 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 # ):

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).

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':

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:

dbms.connector.bolt.tls_level=DISABLED

And then restart your neo4j instance

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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