Search code examples
javaspring-bootneo4jspring-dataspring-data-neo4j-4

How can I use the Bolt driver with Spring Boot/Data Neo4j


I get this error from Spring Boot.

Could not deduce driver to use based on URI 'bolt://localhost:7687

when attempting to configure with properties, or env variable

spring.data.neo4j.uri=bolt://localhost:7687

I did add the driver

   <dependency>
        <scope>runtime</scope>
        <groupId>org.neo4j</groupId>
        <artifactId>neo4j-ogm-bolt-driver</artifactId>
        <version>${neo4j-ogm.version}</version>
    </dependency>

I imagine spring boot doesn't support autoconfiguration for this yet

How can I set this driver up manually to work with Spring Boot / Data? please provide an example.


Solution

  • The current Spring Boot starter for Neo4j does not detect the bolt protocol and so cannot autoconfigure the Bolt driver. However, if you supply a Configuration bean in your application context, Spring Boot will use that, and not attempt to autoconfigure the driver itself.

    This should be enough to get you going:

    @Bean
    public Configuration getConfiguration() {
       Configuration config = new Configuration();
       config
           .driverConfiguration()
           .setURI("bolt://localhost");
       return config;
    }
    

    Note that you don't need to declare the driver name in the configuration, it will be autodetected from the URI.

    Also, note the Configuration class is actually org.neo4j.ogm.config.Configuration, which you'll probably need to use explicitly.