(1) build.gradle jar包引用
//neo4j
implementation "org.springframework.boot:spring-boot-starter-data-neo4j"
(2) db.yml neo4j数据源配置
# 数据源配置
spring:
data:
neo4j:
uri: bolt://127.0.0.1:7687
database: neo4j
username: neo4j
password: pwd
(3)配置类
/*
* Copyright (c) 2020, Shinow All rights reserved.
* Shinow PROPRIETARY/CONFIDENTIAL.
*/
package com.shinow.id.config;
import org.neo4j.ogm.session.SessionFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.neo4j.repository.config.EnableNeo4jRepositories;
import org.springframework.data.neo4j.transaction.Neo4jTransactionManager;
import org.springframework.transaction.annotation.EnableTransactionManagement;
/**
* 类说明:neo4j配置
*
* @author zlw
* @version 1.0
* @date 2021/11/22 09:35
* @since JDK 14.0.2 jdk
*/
@Configuration
@EnableNeo4jRepositories(basePackages = "com.shinow.id.repository")
@EntityScan(basePackages = "com.shinow.id.graph")
@EnableTransactionManagement
public class Neo4jConfig {
/**
* uri
*/
@Value("${spring.data.neo4j.uri}")
private String uri;
/**
* username
*/
@Value("${spring.data.neo4j.username}")
private String username;
/**
* password
*/
@Value("${spring.data.neo4j.password}")
private String password;
@Bean
public org.neo4j.ogm.config.Configuration configuration() {
org.neo4j.ogm.config.Configuration configuration = new org.neo4j.ogm.config.Configuration.Builder()
.uri(uri)
.credentials(username, password)
.build()