MSmedberg MSmedberg - 4 years ago 251
Apache Configuration Question

How to set Neo4J config keys in gremlin-scala?

When running a Neo4J database server standalone (on Ubuntu 14.04), configuration options are set for the global installation in

or possibly

However, when instantiating a Neo4j database from Java or Scala using Apache's
class (
), there is no global installation, and the constructor does not (as far as I can tell) look for any configuration files.

In particular, when running the test suite for my application, I end up with many simultaneous instances of
, which ends up throwing a Address already in use
because all of these instances are trying to communicate over a small range of ports for online backup, which I don't actually need. These channels are set with config options
(default value:
) and
(default value:

My problem would be solved by setting
, or expanding the port range.

Things that have not worked:

  • Creating
    containing the line

  • Creating the same file in my project's

  • Creating the same file in

  • Manually setting the configuration property inside the Scala code:

val db = new Neo4jGraph(dataDirectory)

  • or


  • or


How should I go about setting this property?

Answer Source

Manipulating db.configuration after the database connection had already been opened was definitely futile.

stephen mallette's answer was on the right track, but this particular configuration doesn't appear to pass through in the way his linked example does. There is a naming mismatch between the configuration keys expected in neo4j.conf and those expected in org.neo4j.backup.OnlineBackupKernelExtension. Instead of dbms.backup.address and dbms.backup.enabled, that class looks for config keys online_backup_server and online_backup_enabled.

I was not able to get these keys passed down to the underlying Neo4jGraphAPI instance correctly. What I had to do, instead, was the following:

import org.neo4j.tinkerpop.api.impl.Neo4jFactoryImpl
import scala.collection.JavaConverters._

val factory = new Neo4jFactoryImpl()
val config = Map(
    "online_backup_enabled" -> "true",
    "online_backup_server" -> ""
val db =,config))

With this initialization, the instance correctly listened for backups on port 6350; changing "true" to "false" disabled backup listening.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download