简体   繁体   中英

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.

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.

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

I'm getting ' unknown protocol: bolt ' in this case.

Problem is that DriverConfiguration.setURI() will try to instantiate java.net.URL to retrieve userName , password and to set driver. I think it is better to use java.net.URI because we don't need to open connection, but only to get info.

Check this post: why does java's URL class not recognize certain protocols?

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