Neo4jConfiguration中的Neo4jServer-4.1.0? [英] Neo4jServer in Neo4jConfiguration - 4.1.0?

查看:350
本文介绍了Neo4jConfiguration中的Neo4jServer-4.1.0?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在使用4.1.0-BUILD-SNAPSHOT中的最新代码,因为我需要在4.1分支中修复一些新的错误,并且刚刚注意到"neo4jServer()"不再是Neo4jConfiguration公开的方法.初始化服务器连接和内存版本以进行单元测试的新方法是什么?在我分别使用"RemoteServer"和"InProcessServer"之前.

I've been using the latest code in 4.1.0-BUILD-SNAPSHOT as I need some of the new bug fixes in the 4.1 branch and just noticed that "neo4jServer()" is no longer a method exposed by Neo4jConfiguration. What is the new way to initialize a server connection and an in-memory version for unit tests? Before I was using "RemoteServer" and "InProcessServer", respectively.

推荐答案

请注意,官方文档很快就会更新.

与此同时:

发生了什么变化

SDN 4.1使用新的Neo4j OGM 2.0库. OGM 2.0引入了API更改,这主要是由于增加了对Embedded以及Remote Neo4j的支持.因此,现在使用适当的Driver而不是使用已弃用的RemoteServerInProcessServer来实现与生产数据库的连接.

SDN 4.1 uses the new Neo4j OGM 2.0 libraries. OGM 2.0 introduces API changes, largely due to the addition of support for Embedded as well as Remote Neo4j. Consequently, connection to a production database is now accomplished using an appropriate Driver, rather than using the RemoteServer or the InProcessServer which are deprecated.

对于测试,我们建议使用EmbeddedDriver.仍然可以创建一个内存中的测试服务器,但是此答案中没有涉及.

For testing, we recommend using the EmbeddedDriver. It is still possible to create an in-memory test server, but that is not covered in this answer.

可用的驱动程序

当前提供以下Driver实现

  • http:org.neo4j.drivers.http.driver.HttpDriver
  • 嵌入式:org.neo4j.drivers.embedded.driver.EmbeddedDriver

用于Bolt协议(Neo4j 3.0)的驱动程序实现将很快面世.

A driver implementation for the Bolt protocol (Neo4j 3.0) will be available soon.

配置驱动程序

有两种方法来配置驱动程序-使用属性文件或通过Java配置.存在这些主题的变体(特别是对于通过凭据的变体),但是现在,以下内容应该可以助您一臂之力:

There are two ways to configure a driver - using a properties file or via Java configuration. Variations on these themes exist (particularly for passing credentials), but for now the following should get you going:


配置Http驱动程序

Http驱动程序通过Http连接到Neo4j服务器并与之通信.如果您的应用程序以客户端-服务器模式运行,则必须使用Http驱动程序.请注意,Http驱动程序将尝试连接到在单独进程中运行的服务器. 不能用于启动进程内服务器.

The Http Driver connects to and communicates with a Neo4j server over Http. An Http Driver must be used if your application is running in client-server mode. Please note the Http Driver will attempt to connect to a server running in a separate process. It can't be used for spinning up an in-process server.

属性文件配置:

使用属性文件的优点是它不需要更改Spring配置.

The advantage of using a properties file is that it requires no changes to your Spring configuration.

在类路径的某处创建一个名为ogm.properties的文件.它应包含以下条目:

Create a file called ogm.properties somewhere on your classpath. It should contain the following entries:

  driver=org.neo4j.ogm.drivers.http.driver.HttpDriver
  URI=http://user:password@localhost:7474

Java配置:

配置驱动程序的最简单方法是创建一个Configuration bean,并将其作为第一个参数传递给您的Spring配置中的SessionFactory构造函数:

The simplest way to configure the Driver is to create a Configuration bean and pass it as the first argument to the SessionFactory constructor in your Spring configuration:

import org.neo4j.ogm.config.Configuration;
...

@Bean 
public Configuration getConfiguration() {
   Configuration config = new Configuration();
   config
       .driverConfiguration()
       .setDriverClassName
        ("org.neo4j.ogm.drivers.http.driver.HttpDriver")
       .setURI("http://user:password@localhost:7474");
   return config;
}

@Bean 
public SessionFactory getSessionFactory() {
    return new SessionFactory(getConfiguration(), <packages> );
}


配置嵌入式驱动程序

嵌入式驱动程序直接连接到Neo4j数据库引擎.不涉及服务器,因此您的应用程序代码和数据库之间没有网络开销.如果您不想使用客户端-服务器模型,或者您的应用程序正在作为Neo4j非托管扩展运行,则应使用嵌入式驱动程序.

The Embedded Driver connects directly to the Neo4j database engine. There is no server involved, therefore no network overhead between your application code and the database. You should use the Embedded driver if you don't want to use a client-server model, or if your application is running as a Neo4j Unmanaged Extension.

您可以指定一个永久的数据存储位置,以在应用程序关闭后提供数据的持久性,也可以使用一个永久的数据存储,该数据存储仅在您的应用程序运行时才存在(理想的测试方法).

You can specify a permanent data store location to provide durability of your data after your application shuts down, or you can use an impermanent data store, which will only exist while your application is running (ideal for testing).

在类路径的某处创建一个名为ogm.properties的文件.它应包含以下条目:

Create a file called ogm.properties somewhere on your classpath. It should contain the following entries:

属性文件配置(永久数据存储)

driver=org.neo4j.ogm.drivers.embedded.driver.EmbeddedDriver
URI=file:///var/tmp/graph.db

属性文件配置(永久数据存储)

driver=org.neo4j.ogm.drivers.embedded.driver.EmbeddedDriver

要使用非永久性数据存储,只需省略URI属性.

To use an impermanent data store, simply omit the URI property.

Java配置

用于配置嵌入式驱动程序的技术与用于Http驱动程序的技术相同.设置一个Configuration bean并将其作为第一个参数传递给SessionFactory构造函数:

The same technique is used for configuring the Embedded driver as for the Http Driver. Set up a Configuration bean and pass it as the first argument to the SessionFactory constructor:

import org.neo4j.ogm.config.Configuration;
...

@Bean 
public Configuration getConfiguration() {
   Configuration config = new Configuration();
   config
       .driverConfiguration()
       .setDriverClassName
        ("org.neo4j.ogm.drivers.embedded.driver.EmbeddedDriver")
       .setURI("file:///var/tmp/graph.db");
   return config;
}

@Bean 
public SessionFactory getSessionFactory() {
    return new SessionFactory(getConfiguration(), <packages> );
}

如果您要使用永久性数据存储(例如,用于测试),请不要在配置"上设置URI属性:

If you want to use an impermanent data store (e.g. for testing) do not set the URI attribute on the Configuration:

@Bean 
public Configuration getConfiguration() {
   Configuration config = new Configuration();
   config
       .driverConfiguration()
       .setDriverClassName
        ("org.neo4j.ogm.drivers.embedded.driver.EmbeddedDriver")
   return config;
}

这篇关于Neo4jConfiguration中的Neo4jServer-4.1.0?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆