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?

相關問題