Steven Luo
Steven Luo

Reputation: 2538

Spring-data-neo4j multiple graphs

I know there's some similar topic out there, but none of them gives a solution. So, if using Spring-data-neo4j, is there any way to connect to multiple graphs? NOT graphs in the same instance with different labels.

Or equivalently, I can ask this question:

How can I configure spring-data-neo4j to have multiple sessions to different Neo4j instances on different ports.

Thanks.

EDIT

Thanks to @Hunger, I think I am one step forward. Now the question is: how to confiture spring-data-neo4j to have multiple 'PereistenceContext' and each of them refers to an individual Neo4j instance.

Upvotes: 0

Views: 411

Answers (2)

Yuriy Dubyna
Yuriy Dubyna

Reputation: 92

How about having multiple configurations :

//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();
 }
}

and another one

//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();
 }
}

Upvotes: 0

Michael Hunger
Michael Hunger

Reputation: 41676

You can configure different application contexts with different REST-API's declared pointing to different databases.

You should not mix objects or sessions from those different databases though. So you might need qualifiers for injection.

Upvotes: 1

Related Questions