Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to connect multiple Neo4j databases in a Spring Boot project

Shulou Source: shulou.com Published: 2022-06-01 16:33:20 11月15日 Update

This article focuses on "how to connect multiple Neo4j databases in a Spring Boot project". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to connect multiple Neo4j databases in a Spring Boot project.

problem

I want to use different Neo4j-OGM instances in my Spring Boot application through different Neo4j session factories. I have several domains, each with its own entity class and repository, and each domain with its own instance of Neo4j. I added Spring Boot Starter Data Neo4j, but it only allows one connection, and all my repositories use it.

Solution

To do this, you need the latest version of Spring Boot 2.x and Spring Data, which is called Spring Data Lovelace (RC1). In a standard Spring Boot 2 application generated by start.spring.io, you will change the Spring Data Release series with the following properties: pom.xml

Lovelace-RELEASE

Then the solution can be broken down into two problems 1. Multiple connections to Spring Data Neo4j are provided by reusing the Neo4jProperties in Spring Boot to configure Neo4j. two。 Configure session factory for Spring Data Neo4j.

Implementation code

The following code is located in the sample projects using-multiple-session-factories/Domain1Config.java and Domain2Config.java of this article. The Spring Boot application uses the following configuration application.properties

# Configuration for entities and repositories in "domain1" spring.data.neo4j.username = neo4jspring.data.neo4j.password = domain1spring.data.neo4j.uri = bolt://localhost:7687# Configuration for entities and repositories in "domain2" spring.data.neo4j.domain2.username = neo4jspring.data.neo4j.domain2.password = domain2spring.data.neo4j.domain2.uri = bolt://localhost:7688 so far, I believe you have a better understanding of "how to connect multiple Neo4j databases in a Spring Boot project" You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Tags: Multiple projects data databases applications applications configurations differences code content examples solutions problems storage learning practical deeper for this Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Information Microsoft Huawei macOS MySQL