2016-08-19 40 views
2

我从Spring Boot中得到这个错误。我怎样才能使用弹簧启动/数据Neo4j螺栓驱动器

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

试图与性能配置,或env中时可变

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

我并添加驱动程序

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

imagine spring boot doesn't support autoconfiguration for this yet

我如何手动设置此驱动程序了使用Spring Boot/Data?请举个例子。

+0

这个程序似乎显示的Neo4j-OGM +弹簧启动(虽然使用Groovy),所以看起来像它的支持。 https://github.com/neo4j-examples/neo4j-ogm-university/tree/2.0 –

+0

@ icyrock.com https://github.com/neo4j-examples/neo4j-ogm-university/blob/2.0/src/ main/resources/ogm.properties看起来像是使用http,它们不是弹簧引导属性,但它可能是一种方法来做到这一点 – xenoterracide

回答

5

目前用于Neo4j的Spring Boot启动程序未检测到bolt协议,因此无法自动配置螺栓驱动程序。但是,如果您在应用程序上下文中提供配置Bean,则Spring Boot将使用该配置,并且不会尝试自动配置驱动程序本身。

这应该足以让你去:

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

请注意,您不需要在配置声明驱动程序的名称,它将从URI进行自动检测。

此外,请注意Configuration类实际上是org.neo4j.ogm.config.Configuration,您可能需要明确使用它。

+2

对于未来的读者,属性起作用为引导1.4.1 – xenoterracide

-1

请注意,您不需要在配置中声明驱动程序名称,它将从URI自动检测。

我在'未知协议:螺栓'在这种情况下。

问题是DriverConfiguration.setURI()会尝试实例化java.net.URL来检索userName,password并设置驱动程序。我认为使用java.net.URI更好,因为我们不需要打开连接,但只能获取信息。

检查这个帖子: why does java's URL class not recognize certain protocols?