2016-04-01 109 views
0

我知道那裏有一些類似的話題,但沒有一個給出解決方案。所以,如果使用Spring-data-neo4j,有沒有辦法連接到多個圖表?不是在具有不同標籤的同一實例中繪製圖形。Spring-data-neo4j多圖

或等價,我可以問這樣一個問題:

如何配置彈簧數據的Neo4j不得不在不同的端口不同Neo4j的情況下多個會話。

感謝。

編輯

感謝@Hunger,我覺得我是一個進步。現在的問題是:如何使spring-data-neo4j具有多個「PereistenceContext」,並且它們中的每一個都指向單個Neo4j實例。

+0

你使用哪個版本? –

+0

我正在使用Spring-data-neo4j 4.0.0.RELEASE和Neo4j 2.3.2。 –

回答

1

您可以配置不同的應用程序上下文,並將不同的REST-API聲明爲指向不同的數據庫。

不應該混合來自這些不同數據庫的對象或會話。 所以你可能需要限定符注射。

+0

這聽起來像一個很好的ides。有沒有文件?有一件事打擾我如何告訴倉庫使用哪個會話?例如,在像@Query(「MATCH(n)RETURN n」)這樣的密碼中。 –

0

如何有多種配置:

//First configuration 
@Configuration 
@EnableNeo4jRepositories(basePackages = "org.neo4j.example.repository.dev") 
@EnableTransactionManagement 
public class MyConfigurationDev extends Neo4jConfiguration { 

@Bean 
public Neo4jServer neo4jServer() { 
    return new RemoteServer("http://localhost:7474"); 
} 

@Bean 
public SessionFactory getSessionFactory() { 
    // with domain entity base package(s) 
    return new SessionFactory("org.neo4j.example.domain.dev"); 
} 

// needed for session in view in web-applications 
@Bean 
@Scope(value = "session", proxyMode = ScopedProxyMode.TARGET_CLASS) 
public Session getSession() throws Exception { 
    return super.getSession(); 
} 
} 

,另一個

//Second config 
@Configuration 
@EnableNeo4jRepositories(basePackages = "org.neo4j.example.repository.test") 
@EnableTransactionManagement 
public class MyConfigurationDev extends Neo4jConfiguration { 

@Bean 
public Neo4jServer neo4jServer() { 
    return new RemoteServer("http://localhost:7475"); 
} 

@Bean 
public SessionFactory getSessionFactory() { 
    // with domain entity base package(s) 
    return new SessionFactory("org.neo4j.example.domain.test"); 
} 

// needed for session in view in web-applications 
@Bean 
@Scope(value = "session", proxyMode = ScopedProxyMode.TARGET_CLASS) 
public Session getSession() throws Exception { 
    return super.getSession(); 
} 
}