2016-04-01 108 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(); 
} 
}