Search code examples
neo4jneo4j-ogm

Driver null while opening session in Neo4j OGM Java driver v2


I put ogm.properties file in the same folder as class Neo4jSessionFactory. When I run my project I get information that driver is "null". What is the problem? I use Neo4j OGM driver for Java in version 2.

My session factory class:

public class Neo4jSessionFactory {
  private final static SessionFactory sessionFactory =
                                new SessionFactory("school.domain");
  private static final Neo4jSessionFactory factory = new Neo4jSessionFactory();

  public static Neo4jSessionFactory getInstance() {
    return factory;
  }

  public Session getNeo4jSession() {
    return sessionFactory.openSession();
  }
}

Stack trace:

Exception in thread "main" org.neo4j.ogm.exception.ServiceNotFoundException: Driver: null
    at org.neo4j.ogm.service.DriverService.load(DriverService.java:51)
    at org.neo4j.ogm.service.DriverService.load(DriverService.java:63)
    at org.neo4j.ogm.service.Components.loadDriver(Components.java:126)
    at org.neo4j.ogm.service.Components.driver(Components.java:84)
    at org.neo4j.ogm.session.SessionFactory.openSession(SessionFactory.java:80)
    at neo4jCMS.Neo4jSessionFactory.getNeo4jSession(Neo4jSessionFactory.java:27)
    at neo4jCMS.Application.main(Application.java:20)

My ogm.properties file:

driver=org.neo4j.ogm.drivers.http.driver.HttpDriver
URI=http://login:password@localhost:7474

Solution

  • I put ogm.properties file in the same folder as class Neo4jSessionFactory.

    The easiest way to use the ogm.properties is to put them at the root of the classpath. You don't need to put it in the same folder as the Neo4jSessionFactory or where you instantiate the factory in your app.