How to create a neo4j BoltDriver Datasource and connect…
I wanted to test the neo4j database access using a data source defined in Wildfly server. I used Wildfly 10.1.0 release. I wanted to use the driver with bolt protocol to observe the performance when using it.
First, you need to download the neo4j BoltDriver and add into the library path of wildlfy. Download the latest jdbc driver for neo4j from release page https://github.com/neo4j-contrib/neo4j-jdbc/releases. You can see more details about the bolt protocol in https://boltprotocol.org/ website. I used https://github.com/neo4j-contrib/neo4j-jdbc/releases/download/3.1.0/neo4j-jdbc-driver-3.1.0.jar. It contains the BoltDriver as well.
Create the folder structure as follows wildfly-10.1.0.Final/modules/system/layers/base/org/neo4j/main
Then add the module.xml
file with the following content. Copy the driver jar package to the same folder.
<?xml version="1.0" encoding="UTF-8"?> <module xmlns="urn:jboss:module:1.3" name="org.neo4j"> <resources> <resource-root path="neo4j-jdbc-driver-3.1.0.jar"/> </resources> <dependencies> <module name="javax.api"/> <module name="javax.transaction.api"/> <module name="sun.jdk"/> </dependencies> </module>
Now you can define the driver and the data source in the standalone-full.xml
. Browse into wildfly-10.1.0.Final/standalone/configuration
and edit the configuration file with a text editor. I used vim.
vim standalone-full.xml
Afterwards, add the datasource and neo4j connector to standalone-full.xml
file.
<datasources> <datasource jndi-name="java:jboss/datasources/neo4jTestDS" pool-name="neo4jTestDS" enabled="true" use-java-context="true"> <connection-url>jdbc:neo4j:bolt://localhost:7687/</connection-url> <driver>neo4j</driver> <security> <user-name>username</user-name> <password>password</password> </security> </datasource> <drivers> <driver name="neo4j" module="org.neo4j"> <xa-datasource-class>org.neo4j.jdbc.bolt.BoltDriver</xa-datasource-class> </driver> </drivers> </datasources>
Now the server configuration is done. Next step is to access this datasource in your service app or web app.
@Resource(mappedName = "java:jboss/datasources/Neo4jDS") private DataSource dataSource;
You can use the datasource in a DAO or a Repository service or directly inject into whatever the service you want.
Enjoy!